telegram: Add support for topics. (#184)
This commit is contained in:
parent
bf3170cb6f
commit
775fb89cf6
|
@ -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]
|
||||||
|
|
|
@ -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),
|
||||||
]
|
]
|
||||||
|
|
|
@ -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(
|
||||||
|
|
|
@ -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):
|
||||||
|
|
|
@ -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"
|
||||||
|
|
Loading…
Reference in New Issue