Files
taro-bot-python/bot/msteams/conversation.py
Björn Benouarets ee9903b704 init: Initial commit
2026-01-19 14:14:54 +01:00

58 lines
1.8 KiB
Python

import requests
from bot.msteams.auth import Auth
from bot.msteams.adaptivecard.card import AdaptiveCard
#
class Conversation:
def __init__(self, auth: Auth) -> None:
self.auth = auth
def new_conversation(self, channel_id: str, message: str) -> None:
access_token = str(self.auth)
url = "https://smba.trafficmanager.net/emea/v3/conversations"
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
data = {
"isGroup": True,
"channelData": {
"channel": {
"id": channel_id
}
},
"activity": {
"type": "message",
"text": message
}
}
response = requests.post(url, headers=headers, json=data)
return response.json()
def new_conversation_with_card(self, channel_id: str, card: AdaptiveCard) -> None:
access_token = str(self.auth)
url = "https://smba.trafficmanager.net/emea/v3/conversations"
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
data = {
"isGroup": True,
"channelData": {
"channel": {
"id": channel_id,
}
},
"activity": {
"type": "message",
"text": "",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": card.data
}
]
}
}
response = requests.post(url, headers=headers, json=data)
return response.json()