Skip to content

Commit c058315

Browse files
Setup python package + fork off MM-API stuff from other repo.
1 parent ac29fb8 commit c058315

File tree

6 files changed

+1938
-0
lines changed

6 files changed

+1938
-0
lines changed

README.md

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
# [Mattermost API](https://api.mattermost.com/) bindings
2+
In productive use on a 6k+ users E10 instance at https://mattermost.fsinf.at
3+
+ Used to manage channels, users and everything.
4+
+ Some api-endpoints are #UNTESTED.
5+
+ Some are not handled/#NOT_IMPLEMENTED (yet).
6+
+ Some dont seem to make any sense to ever implement at all. Why do they even exist?
7+
+ Others may be out of scope (I cannot test E20-stuff)
8+
+ Beware: I love to rebase git. :)
9+
10+
## If you use this or find this stuff useful, consider paying me a beer/club-mate :)
11+
+ ``btc: bc1q9vxqzd58683ky9c2yaddaxx3wrxakggfa0dmdt``
12+
+ ``eth: 0x839326860d74cf61f03719c5c63db3ae5d2b443f``
13+
+ ``bch: qqxpm8py3flkaqdt4ehatzvx250634fuvgsgvft6z4``
14+
+ ``doge: DLeQq2u7gdnidaNwEtj9fYrstUaU4banNg``
15+
+ ``xmr: 47WwuQssrZRHLXYBRoEPmqhyG8e4PxorwWn1Xvyg6QShKAjZ83UHWJmYd9PFkpH6vPQFgNbnKvaRz1EzoQHSeeQvEGQ6ihA``
16+
17+
18+
## Setup
19+
``pip3 install --user --upgrade mattermost``
20+
21+
22+
## Usage
23+
```
24+
import mattermost
25+
26+
# login
27+
mm = mattermost.MMApi("https://mattermost.example.com/api")
28+
mm.login("[email protected]", "my-pw")
29+
# alternatively use a personal-access-token/bot-token.
30+
# mm.login(bearer="my-personal-access-token")
31+
32+
33+
# do stuff (print info about your user)
34+
import pprint
35+
pprint.pprint(mm.get_user())
36+
37+
38+
# do other stuff (print info about an not-existing user)
39+
try:
40+
pprint.pprint(mm.get_user("not-existing-user-id", exc=True))
41+
except mattermost.ApiException as e:
42+
print(e)
43+
44+
45+
# custom endpoint call (get server config)
46+
cfg = mm._get("/v4/config")
47+
48+
# do something (enable plugins)
49+
cfg["PluginSettings"]["Enable"] = True
50+
51+
# custom endpoint call (put server config)
52+
mm._put("/v4/config", data=cfg)
53+
54+
55+
# logout
56+
mm.revoke_user_session()
57+
```
58+
59+
60+
### Websocket usage
61+
```
62+
import mattermost
63+
import mattermost.ws
64+
65+
# login
66+
mm = mattermost.MMApi("https://mattermost.example.com/api")
67+
mm.login("[email protected]", "my-pw")
68+
69+
70+
# define a websocket handler
71+
def webs_handler(mmws, event_data):
72+
import pprint
73+
pprint.pprint(mmws)
74+
pprint.pprint(event_data)
75+
76+
# connect to websocket and start processing events
77+
mmws = mattermost.ws.MMws(webs_handler, mm, "wss://mattermost.example.com/api/v4/websocket")
78+
```
79+
80+
To close the websocket connection - there is no way to restart, create a new instance of MMws:
81+
+ ``mmws.close_websocket()``
82+
83+
84+
### Manually calling the API
85+
Some endpoints are not handled (yet). You can manually call these endpoints. Available private functions:
86+
+ ``_get(endpoint, raw=False, exc=False)``
87+
+ ``_put(endpoint, data=None, exc=False)``
88+
+ ``_post(endpoint, data=None, multipart_formdata=None, exc=False)``
89+
+ ``_delete(endpoint, data=None, exc=False)``
90+
91+
92+
### stdin2channel
93+
You can pipe ``STDIN`` to a channel:
94+
+ ``echo "message" | python3 -m mattermost.stdin2channel https://localhost:8065/api '[email protected]' 'my-pw' 'channel_id'``
95+
**This leaks your credentials to everyone on your system!** Only use this in trusted dev-envs.
96+
97+
98+
## Endpoints
99+
Ordered by https://api.mattermost.com/
100+
<!-- grep -E "(^#\+)|(def\s+[^_])" mattermost/__init__.py | sed -nEe 's/^#\+/+/p' -e 's/^\s+def\s+([^(]+)\(self,?\s*(.*\)):?(.*$)/ + **``\1 (\2\3``**/p' -e 's/^\s+#def\s+(.*NOT_IMPLEMENTED.*$)/ + *``\1``*/' >> README.md -->
101+
+ **LOGIN/LOGOUT**
102+
+ **``login (login_id=None, password=None, token=None, bearer=None)``**
103+
+ **``logout (**kwargs)``**
104+
+ **USERS**
105+
+ *``create_user() #NOT_IMPLEMENTED``*
106+
+ **``get_users (in_team=None, not_in_team=None, in_channel=None, not_in_channel=None, group_constrained=None, without_team=None, sort=None, **kwargs)``**
107+
+ **``get_users_by_ids_list (user_ids_list, **kwargs) #UNTESTED``**
108+
+ **``get_users_by_group_channel_ids_list (group_channel_ids_list, **kwargs) #UNTESTED``**
109+
+ **``get_users_by_usernames_list (usernames_list, **kwargs)``**
110+
+ *``search_users() #NOT_IMPLEMENTED``*
111+
+ *``autocomplete_users() #NOT_IMPLEMENTED``*
112+
+ *``get_user_ids_of_known_users() #NOT_IMPLEMENTED``*
113+
+ *``get_total_count_of_users_in_system() #NOT_IMPLEMENTED``*
114+
+ **``get_user (user_id=None, **kwargs)``**
115+
+ *``update_user() #NOT_IMPLEMENTED: # use patch_user``*
116+
+ *``deactivate_user() #NOT_IMPLEMENTED``*
117+
+ **``patch_user (user_id, props=None, **kwargs)``**
118+
+ *``update_user_roles() #NOT_IMPLEMENTED``*
119+
+ *``update_user_active_status() #NOT_IMPLEMENTED``*
120+
+ *``get_user_profile_image() #NOT_IMPLEMENTED``*
121+
+ *``set_user_profile_image() #NOT_IMPLEMENTED``*
122+
+ *``delete_user_profile_image() #NOT_IMPLEMENTED``*
123+
+ *``get_user_default_profile_image() #NOT_IMPLEMENTED``*
124+
+ **``get_user_by_username (username, **kwargs)``**
125+
+ *``reset_user_password() #NOT_IMPLEMENTED``*
126+
+ *``update_user_mfa() #NOT_IMPLEMENTED``*
127+
+ *``generate_user_mfa_secret() #NOT_IMPLEMENTED``*
128+
+ **``demote_a_user (user_id, **kwargs)``**
129+
+ **``promote_a_guest (user_id, **kwargs)``**
130+
+ *``check_user_mfa() #NOT_IMPLEMENTED``*
131+
+ *``update_user_password() #NOT_IMPLEMENTED``*
132+
+ *``send_user_password_reset_mail() #NOT_IMPLEMENTED``*
133+
+ *``get_user_by_email() #NOT_IMPLEMENTED``*
134+
+ **``get_user_sessions (user_id=None, **kwargs)``**
135+
+ **``revoke_user_session (user_id=None, session_id=None, **kwargs)``**
136+
+ *``revoke_all_user_sessions() #NOT_IMPLEMENTED``*
137+
+ *``attach_mobile_device_to_user_session() #NOT_IMPLEMENTED``*
138+
+ *``get_user_audit() #NOT_IMPLEMENTED``*
139+
+ *``admin_verify_user_email_() #NOT_IMPLEMENTED``*
140+
+ *``verify_user_email_() #NOT_IMPLEMENTED``*
141+
+ *``send_user_email_verification() #NOT_IMPLEMENTED``*
142+
+ *``switch_user_login_method() #NOT_IMPLEMENTED``*
143+
+ *``create_user_access_token() #NOT_IMPLEMENTED``*
144+
+ *``get_user_access_tokens() #NOT_IMPLEMENTED``*
145+
+ *``revoke_user_access_token() #NOT_IMPLEMENTED``*
146+
+ *``get_user_access_token() #NOT_IMPLEMENTED``*
147+
+ *``disable_user_access_token() #NOT_IMPLEMENTED``*
148+
+ *``enable_user_access_token() #NOT_IMPLEMENTED``*
149+
+ *``search_user_access_tokens() #NOT_IMPLEMENTED``*
150+
+ *``update_user_auth_method() #NOT_IMPLEMENTED``*
151+
+ *``record_user_action_custom_tos() #NOT_IMPLEMENTED``*
152+
+ *``fetch_user_latest_accepted_custom_tos() #NOT_IMPLEMENTED``*
153+
+ *``revoke_all_users_all_sessions() #NOT_IMPLEMENTED #MM, ARE YOU INSANE?!``*
154+
+ **BOTS** #NOT_IMPLEMENTED
155+
+ **TEAMS**
156+
+ *``create_team() #NOT_IMPLEMENTED``*
157+
+ **``get_teams (include_total_count=None, **kwargs)``**
158+
+ **``get_team (team_id, **kwargs)``**
159+
+ *``update_team() #NOT_IMPLEMENTED``*
160+
+ *``delete_team() #NOT_IMPLEMENTED``*
161+
+ *``patch_team() #NOT_IMPLEMENTED``*
162+
+ *``update_team_privacy() #NOT_IMPLEMENTED``*
163+
+ *``restore_team() #NOT_IMPLEMENTED``*
164+
+ *``get_team_by_name() #NOT_IMPLEMENTED``*
165+
+ *``search_teams() #NOT_IMPLEMENTED``*
166+
+ *``exists_team() #NOT_IMPLEMENTED``*
167+
+ *``get_teams_for_user() #NOT_IMPLEMENTED``*
168+
+ **``get_team_members (team_id, **kwargs)``**
169+
+ **``add_user_to_team (team_id, user_id, **kwargs)``**
170+
+ *``add_user_to_team_from_invite() #NOT_IMPLEMENTED``*
171+
+ *``add_multiple_users_to_team() #NOT_IMPLEMENTED WHY?!``*
172+
+ *``get_team_members_for_a_user() #NOT_IMPLEMENTED WHY NOT NAMING STUFF USEFULLY?!``*
173+
+ **``get_team_member (team_id, user_id, **kwargs)``**
174+
+ **``remove_user_from_team (team_id, user_id, **kwargs)``**
175+
+ *``get_team_members_by_id() #NOT_IMPLEMENTED``*
176+
+ *``get_team_stats() #NOT_IMPLEMENTED``*
177+
+ *``regenerate_team_invite_id() #NOT_IMPLEMENTED``*
178+
+ *``get_team_icon() #NOT_IMPLEMENTED``*
179+
+ *``set_team_icon() #NOT_IMPLEMENTED``*
180+
+ *``remove_team_icon() #NOT_IMPLEMENTED``*
181+
+ *``update_team_members_roles() #NOT_IMPLEMENTED``*
182+
+ **``update_team_members_scheme_roles (team_id, user_id, data, **kwargs)``**
183+
+ *``get_team_unreads_for_user() #NOT_IMPLEMENTED``*
184+
+ *``get_team_unreads() #NOT_IMPLEMENTED``*
185+
+ *``invite_users_to_team_by_email() #NOT_IMPLEMENTED``*
186+
+ *``invite_guests_to_team_by_email() #NOT_IMPLEMENTED``*
187+
+ *``invalidate_invites_to_team_by_email() #NOT_IMPLEMENTED``*
188+
+ *``import_team() #NOT_IMPLEMENTED``*
189+
+ *``get_team_invite_info() #NOT_IMPLEMENTED``*
190+
+ *``set_team_scheme() #NOT_IMPLEMENTED``*
191+
+ *``get_team_members_minus_group_members() #NOT_IMPLEMENTED``*
192+
+ **``get_team_channels (team_id, **kwargs) #This belongs here, not to channels!``**
193+
+ **CHANNELS**
194+
+ *``get_all_channels() #NOT_IMPLEMENTED NOT USEFUL AT ALL!``*
195+
+ **``create_channel (team_id, name, display_name, purpose=None, header=None, chan_type="O", **kwargs)``**
196+
+ **``create_dm_channel_with (other_user_id, **kwargs)``**
197+
+ **``create_group_channel_with (other_user_ids_list, **kwargs) #UNTESTED``**
198+
+ *``search_all_private_and_public_channels() #NOT_IMPLEMENTED``*
199+
+ *``search_all_users_group_channels() #NOT_IMPLEMENTED``*
200+
+ *``get_team_channels_by_id() #NOT_IMPLEMENTED``*
201+
+ *``get_timezones_of_users_in_channel() #NOT_IMPLEMENTED``*
202+
+ **``get_channel (channel_id, **kwargs)``**
203+
+ **``update_channel (channel_id, props, **kwargs)``**
204+
+ **``patch_channel (channel_id, props, **kwargs)``**
205+
+ **``get_channel_posts_pinned (channel_id, **kwargs)``**
206+
+ **``search_channel (team_id, term, **kwargs)``**
207+
+ **``get_channel_by_name (team_id, channel_name, **kwargs)``**
208+
+ **``get_channel_members (channel_id, **kwargs)``**
209+
+ **``get_channel_member (channel_id, user_id, **kwargs)``**
210+
+ **``add_user_to_channel (channel_id, user_id, **kwargs)``**
211+
+ **``remove_user_from_channel (channel_id, user_id, **kwargs)``**
212+
+ **``get_channel_members_for_user (user_id, team_id, **kwargs)``**
213+
+ **``get_channels_for_user (user_id, team_id, **kwargs)``**
214+
+ **``update_channel_members_scheme_roles (channel_id, user_id, props, **kwargs)``**
215+
+ **POSTS**
216+
+ **``create_post (channel_id, message, props={"from_webhook":"true"}, filepaths=[], root_id=None, **kwargs)``**
217+
+ **``create_ephemeral_post (channel_id, message, user_id, **kwargs)``**
218+
+ **``get_post (post_id, **kwargs)``**
219+
+ **``delete_post (post_id, **kwargs)``**
220+
+ **``patch_post (post_id, message, props, **kwargs)``**
221+
+ **``get_posts_for_channel (channel_id, **kwargs)``**
222+
+ **FILES**
223+
+ **``upload_file (channel_id, filepath, **kwargs)``**
224+
+ **``get_file (file_id, **kwargs)``**
225+
+ **PREFERENCES** #NOT_IMPLEMENTED
226+
+ **STATUS** #NOT_IMPLEMENTED
227+
+ **EMOJI** #NOT_IMPLEMENTED
228+
+ **REACTIONS**
229+
+ **``create_reaction (user_id, post_id, emoji_name, **kwargs)``**
230+
+ **WEBHOOKS**
231+
+ **``create_outgoing_hook (team_id, channel_id, description="", display_name="", trigger_words=[], trigger_when=0, callback_urls=[], **kwargs)``**
232+
+ **``list_outgoing_hooks (team_id, channel_id, **kwargs)``**
233+
+ **``delete_outgoing_hook (hook_id, **kwargs)``**
234+
+ **COMMANDS**
235+
+ **``create_slash_command (team_id, command, url, **kwargs)``**
236+
+ **``list_custom_slash_commands_per_team (team_id, **kwargs)``**
237+
+ **``update_slash_command (data, **kwargs)``**
238+
+ **``delete_slash_command (command_id, **kwargs)``**
239+
+ **OPENGRAPH** #NOT_IMPLEMENTED
240+
+ **SYSTEM** #NOT_IMPLEMENTED
241+
+ **BRAND** #NOT_IMPLEMENTED
242+
+ **OAUTH** #NOT_IMPLEMENTED
243+
+ **SAML** #NOT_IMPLEMENTED
244+
+ **LDAP** #NOT_IMPLEMENTED
245+
+ **GROUPS** #NOT_IMPLEMENTED
246+
+ **COMPLIANCE** #NOT_IMPLEMENTED
247+
+ **CLUSTER** #NOT_IMPLEMENTED
248+
+ **ELASTICSEARCH** #NOT_IMPLEMENTED
249+
+ **BLEVE** #NOT_IMPLEMENTED
250+
+ **DATARETENTION** #NOT_IMPLEMENTED
251+
+ **JOBS** #NOT_IMPLEMENTED
252+
+ **PLUGINS** #NOT_IMPLEMENTED
253+
+ **ROLES** #NOT_IMPLEMENTED
254+
+ **SCHEMES** #NOT_IMPLEMENTED
255+
+ **INTEGRATION ACTIONS**
256+
+ **``open_dialog (trigger_id, response_url, dialog, **kwargs)``**
257+
+ **TERMS OF SERVICE** #NOT_IMPLEMENTED

0 commit comments

Comments
 (0)