publishers: zulip: Let the user specify their instance. (#95)
This commit is contained in:
parent
5335ed8cc3
commit
f12992c5d9
|
@ -7,6 +7,7 @@ username="xxx"
|
|||
active=false
|
||||
[default.publisher.zulip]
|
||||
active=true
|
||||
instance="xxx"
|
||||
chat_id="xxx"
|
||||
subject="xxx"
|
||||
bot_token="xxx"
|
||||
|
@ -31,6 +32,7 @@ token="xxx"
|
|||
username="xxx"
|
||||
[default.notifier.zulip]
|
||||
active=true
|
||||
instance="xxx"
|
||||
chat_id="xxx"
|
||||
subject="xxx"
|
||||
bot_token="xxx"
|
||||
|
|
|
@ -14,6 +14,7 @@ zulip_validators = [
|
|||
Validator("notifier.zulip.bot_email", must_exist=True),
|
||||
]
|
||||
mastodon_validators = [
|
||||
Validator("publisher.zulip.instance", must_exist=True),
|
||||
Validator("notifier.mastodon.instance", must_exist=True),
|
||||
Validator("notifier.mastodon.token", must_exist=True),
|
||||
Validator("notifier.mastodon.name", must_exist=True),
|
||||
|
|
|
@ -12,6 +12,7 @@ telegram_validators = [
|
|||
Validator("publisher.telegram.username", must_exist=True),
|
||||
]
|
||||
zulip_validators = [
|
||||
Validator("publisher.zulip.instance", must_exist=True),
|
||||
Validator("publisher.zulip.chat_id", must_exist=True),
|
||||
Validator("publisher.zulip.subject", must_exist=True),
|
||||
Validator("publisher.zulip.msg_template_path", must_exist=True, default=None),
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
from urllib.parse import urljoin
|
||||
|
||||
import pkg_resources
|
||||
import requests
|
||||
from requests import Response
|
||||
|
@ -54,8 +56,7 @@ class ZulipPlatform(AbstractPlatform):
|
|||
"""
|
||||
|
||||
_conf = ("publisher", "zulip")
|
||||
|
||||
api_uri = "https://zulip.twc-italia.org/api/v1/"
|
||||
api_uri = "api/v1/"
|
||||
name = "zulip"
|
||||
|
||||
def _send_private(self, message: str) -> Response:
|
||||
|
@ -63,7 +64,7 @@ class ZulipPlatform(AbstractPlatform):
|
|||
Send private messages
|
||||
"""
|
||||
return requests.post(
|
||||
url=self.api_uri + "messages",
|
||||
url=urljoin(self.conf.instance, self.api_uri) + "messages",
|
||||
auth=HTTPBasicAuth(self.conf.bot_email, self.conf.bot_token),
|
||||
data={"type": "private", "to": f"[{self.user_id}]", "content": message},
|
||||
)
|
||||
|
@ -73,7 +74,7 @@ class ZulipPlatform(AbstractPlatform):
|
|||
Send stream messages
|
||||
"""
|
||||
return requests.post(
|
||||
url=self.api_uri + "messages",
|
||||
url=urljoin(self.conf.instance, self.api_uri) + "messages",
|
||||
auth=HTTPBasicAuth(self.conf.bot_email, self.conf.bot_token),
|
||||
data={
|
||||
"type": "stream",
|
||||
|
@ -88,7 +89,7 @@ class ZulipPlatform(AbstractPlatform):
|
|||
|
||||
res = requests.get(
|
||||
auth=HTTPBasicAuth(self.conf.bot_email, self.conf.bot_token),
|
||||
url=self.api_uri + "users/me",
|
||||
url=urljoin(self.conf.instance, self.api_uri) + "users/me",
|
||||
)
|
||||
data = self._validate_response(res)
|
||||
|
||||
|
|
|
@ -96,6 +96,9 @@ async def setup_db(event_model_generator, publication_model_generator):
|
|||
settings["publisher"]["zulip"][
|
||||
"bot_email"
|
||||
] = "giacomotest2-bot@zulip.twc-italia.org"
|
||||
settings["publisher"]["zulip"][
|
||||
"instance"
|
||||
] = "https://zulip.twc-italia.org"
|
||||
|
||||
await update_publishers(["zulip"])
|
||||
publisher = await Publisher.filter(name="zulip").first()
|
||||
|
|
Loading…
Reference in New Issue