-
Notifications
You must be signed in to change notification settings - Fork 0
/
mattermost_comunication.py
59 lines (46 loc) · 2.08 KB
/
mattermost_comunication.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import mattermostdriver.exceptions
import mattermost_client
from config import config
from mattermost_client import ChannelApi, MMApi
def send_message(file_info, message):
channel_id = file_info["originating_mm_post_channel_id"]
post_id = file_info["originating_mm_post_id"]
# TODO Comment below line, this is for testing purposes
# channel_id = MMApi().get_channel_id("bestuur-dev")
channel = ChannelApi(
channel_id=channel_id,
user=mattermost_client.users[config["mattermost"]["selected_user"]],
)
try:
channel.create_threaded_post(
post_id,
f"{message}",
)
except mattermostdriver.exceptions.InvalidOrMissingParameters as e:
# This will occur when we try to react to a file in a channel that is not the same as the originating channel.
channel.create_post(
f"{message}",
)
def report_newly_found_file(file_info):
git_url = f"https://{config['gitea']['server_url']}/{config['gitea']['remote_org']}/{config['gitea']['remote_repo']}"
message = f"I found a new CodiMD file in this post! Making work of putting it on git :)\n - Requested location in the [drive]({git_url}): {file_info['metadata']['sync-to']}"
send_message(file_info, message)
def report_newly_found_but_invalid_file(file_info):
message = """Hi there! :wave:
I'm your friendly neighbourhood document sync bot.
I could synchronize this CodiMD file automatically to our Git DRIVE for safekeeping, but the necessary metadata block is not present.
You can easily add the correct info and I will do the rest of the work for you!
Just add the following lines to your file, the location in your file is not important but at the top would be my recommendation.
```
:::spoiler git drive sync
- sync-to: <a valid path on the DRIVE, for ex.: verslagen/21-22/2022-05-13.md>
:::
```"""
send_message(file_info, message)
# send_message(
# {
# "originating_mm_post_channel_id": "dm1abp4wfidezmig1yqyu53mmy",
# "originating_mm_post_id": "dm1abp4wfidezmig1yqyu53mmy"
# },
# "haldis_sync is started"
# )