81 lines
2.2 KiB
Python
81 lines
2.2 KiB
Python
from mattermostdriver import Driver
|
|
from django.conf import settings
|
|
from pprint import pprint
|
|
|
|
mattermost = Driver({
|
|
'url': 'chat.addwin.ir',
|
|
# 'login_id': 'sahama',
|
|
# 'password': settings.MATTERMOST_BASE_PUBLICE_URL,
|
|
# 'token': settings.MATTERMOST_TOKEN,
|
|
'token': 'x36shfdd5fnz3qm9ut7crb6xoh',
|
|
|
|
'scheme': 'https',
|
|
'port': 443,
|
|
'basepath': '/api/v4',
|
|
'verify': True, # Or /path/to/file.pem
|
|
# 'mfa_token': 'YourMFAToken',
|
|
|
|
'auth': None,
|
|
'timeout': 30,
|
|
|
|
'request_timeout': None,
|
|
'keepalive': False,
|
|
'keepalive_delay': 5,
|
|
|
|
'websocket_kw_args': None,
|
|
|
|
'debug': True
|
|
})
|
|
|
|
# mattermost.login()
|
|
# mattermost.users.create_user(options={
|
|
# "email": "user2@example.com",
|
|
# "username": "newuser2",
|
|
# "first_name": "John",
|
|
# "last_name": "Doe",
|
|
# "password": "SecurePassword123!",}
|
|
# )
|
|
|
|
|
|
user_client = Driver({
|
|
'url': 'chat.addwin.ir',
|
|
'login_id': 'newuser',
|
|
'password': 'SecurePassword123!',
|
|
# 'token': settings.MATTERMOST_TOKEN,
|
|
|
|
'scheme': 'https',
|
|
'port': 443,
|
|
'basepath': '/api/v4',
|
|
'verify': True, # Or /path/to/file.pem
|
|
# 'mfa_token': 'YourMFAToken',
|
|
|
|
'auth': None,
|
|
'timeout': 30,
|
|
|
|
'request_timeout': None,
|
|
'keepalive': False,
|
|
'keepalive_delay': 5,
|
|
|
|
'websocket_kw_args': None,
|
|
|
|
'debug': True
|
|
})
|
|
|
|
user_client.login()
|
|
# print(user_client.users.get_user_by_username(username='newuser')) # jrrryzhq4bfftchoe1anji6a5c
|
|
# print(user_client.users.get_user_by_username(username='newuser2')) # yy6ew7jy63dnb85ox6skgi969r
|
|
# print(user_client.users.get_user_by_username(username='sahama')) # hqst9xib4typ7fynq3wn4qnzye
|
|
# print(user_client.users.get_user_by_username(username='ghasemi')) # w6ou8xyaqiyw5b8e3bhyae17xw
|
|
print(user_client.channels.create_direct_message_channel(options=["jrrryzhq4bfftchoe1anji6a5c", "w6ou8xyaqiyw5b8e3bhyae17xw"]))
|
|
# exit()
|
|
|
|
print(user_client.posts.create_post(options={
|
|
"channel_id": "76xjniwh3jgdtmitk66nigtktr", # anth9sme4bn9tdantqxx1g4kky
|
|
"message": "پیام از سمت پایتون"
|
|
}))
|
|
|
|
pprint(user_client.posts.get_unread_posts_for_channel(**{
|
|
"channel_id": "anth9sme4bn9tdantqxx1g4kky",
|
|
"user_id": "jrrryzhq4bfftchoe1anji6a5c"
|
|
}))
|
|
|