forked from vgrem/office365-rest-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_message.py
More file actions
20 lines (16 loc) · 704 Bytes
/
send_message.py
File metadata and controls
20 lines (16 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"""
Send a new message in the specified channel or a chat.
https://learn.microsoft.com/en-us/graph/api/chatmessage-post?view=graph-rest-1.0&tabs=http
"""
import sys
from office365.graph_client import GraphClient
from office365.outlook.mail.item_body import ItemBody
from office365.teams.team import Team
from tests.graph_case import acquire_token_by_username_password
client = GraphClient(acquire_token_by_username_password)
my_teams = client.me.joined_teams.get().execute_query()
if len(my_teams) == 0:
sys.exit("No teams found")
target_team = my_teams[1] # type: Team
message = target_team.primary_channel.messages.add(itemBody=ItemBody("Hello world!")).execute_query()
print(message.web_url)