telegram: Add support for topics.

This commit is contained in:
Giacomo Leidi 2023-06-18 13:19:07 +02:00
parent 34ebd8f982
commit 66ca471c97
No known key found for this signature in database
GPG Key ID: D075F59A480549C3
5 changed files with 14 additions and 4 deletions

View File

@ -1,6 +1,7 @@
[default.publisher.telegram] [default.publisher.telegram]
active=true active=true
chat_id="xxx" chat_id="xxx"
message_thread_id="xxx"
token="xxx" token="xxx"
username="xxx" username="xxx"
[default.publisher.zulip] [default.publisher.zulip]
@ -31,6 +32,7 @@ page_access_token="xxx"
[default.notifier.telegram] [default.notifier.telegram]
active=true active=true
chat_id="xxx" chat_id="xxx"
message_thread_id="xxx"
token="xxx" token="xxx"
username="xxx" username="xxx"
[default.notifier.zulip] [default.notifier.zulip]
@ -51,4 +53,4 @@ active=false
[default.notifier.facebook] [default.notifier.facebook]
active=false active=false
page_access_token="xxx" page_access_token="xxx"

View File

@ -4,6 +4,7 @@ from dynaconf import Validator
telegram_validators = [ telegram_validators = [
Validator("notifier.telegram.chat_id", must_exist=True), Validator("notifier.telegram.chat_id", must_exist=True),
Validator("notifier.telegram.message_thread_id", default=None),
Validator("notifier.telegram.token", must_exist=True), Validator("notifier.telegram.token", must_exist=True),
Validator("notifier.telegram.username", must_exist=True), Validator("notifier.telegram.username", must_exist=True),
] ]

View File

@ -3,6 +3,7 @@ from dynaconf import Validator
telegram_validators = [ telegram_validators = [
Validator("publisher.telegram.chat_id", must_exist=True), Validator("publisher.telegram.chat_id", must_exist=True),
Validator("publisher.telegram.message_thread_id", default=None),
Validator("publisher.telegram.msg_template_path", must_exist=True, default=None), Validator("publisher.telegram.msg_template_path", must_exist=True, default=None),
Validator("publisher.telegram.recap_template_path", must_exist=True, default=None), Validator("publisher.telegram.recap_template_path", must_exist=True, default=None),
Validator( Validator(

View File

@ -99,9 +99,14 @@ class TelegramPlatform(AbstractPlatform):
) )
def _send(self, message: str, event: Optional[MobilizonEvent] = None) -> Response: def _send(self, message: str, event: Optional[MobilizonEvent] = None) -> Response:
json_message = {"chat_id": self.conf.chat_id, "text": message, "parse_mode": "html"}
if self.conf.message_thread_id:
json_message["message_thread_id"] = self.conf.message_thread_id
return requests.post( return requests.post(
url=f"https://api.telegram.org/bot{self.conf.token}/sendMessage", url=f"https://api.telegram.org/bot{self.conf.token}/sendMessage",
json={"chat_id": self.conf.chat_id, "text": message, "parse_mode": "html"}, json=json_message,
) )
def _validate_response(self, res): def _validate_response(self, res):

View File

@ -1,6 +1,7 @@
[default] [default]
local_state_dir = "/var/mobilizon_reshare" local_state_dir = "/var/mobilizon_reshare"
db_url = "sqlite:///var/mobilizon_reshare/events.db" log_dir = "@format {this.local_state_dir}"
db_url = "@format sqlite://{this.local_state_dir}/events.db"
locale= "en-us" locale= "en-us"
[default.source.mobilizon] [default.source.mobilizon]
@ -31,7 +32,7 @@ stream = "ext://sys.stderr"
level = "DEBUG" level = "DEBUG"
class = "logging.handlers.RotatingFileHandler" class = "logging.handlers.RotatingFileHandler"
formatter = "standard" formatter = "standard"
filename = "/var/log/mobilizon_reshare/mobilizon_reshare.log" filename = "@format {this.log_dir}/mobilizon_reshare.log"
maxBytes = 52428800 maxBytes = 52428800
backupCount = 500 backupCount = 500
encoding = "utf8" encoding = "utf8"