首页 > 解决方案 > MS 团队机器人 - 创建新对话

问题描述

我正在使用 botbuilder-python 来构建 MS Teams 机器人。以下示例我能够回复消息。我正在努力创建全新的消息,而无需从 Teams 传递现有活动。我修改了测试中的一些代码(https://github.com/Microsoft/botbuilder-python/blob/62b0512a4dd918fa0d3837207012b31213aaedcc/libraries/botframework-connector/tests/test_conversations.py),但我得到:

botbuilder.schema.error_response_py3.ErrorResponseException: (BadSyntax) 无法解析租户 ID

它是什么,我在哪里可以找到它(我可以从请求中找到它,但它并不理想)以及如何传递它?谁能指出我创建新对话的任何 Python 示例?

标签: pythonbotframeworkmicrosoft-teams

解决方案


我想通了,以防万一其他人试图做同样的事情并被卡住:

to = ChannelAccount(id=to_user_id)

bot_channel = ChannelAccount(id=bot_id)
activity_reply = Activity(type=ActivityTypes.message, channel_id='msteams',from_property=bot_channel,recipient=to,text=message)

credentials=MicrosoftAppCredentials(app_id, app_password)
JwtTokenValidation.authenticate_request(activity_reply, "Authorization", credentials)
# That's where you pass the tenant id
reply_conversation_params=ConversationParameters(bot=bot_channel, members=[to], activity=activity_reply, channel_data={ 'tenant': { 'id': tenant_id } })
connector = ConnectorClient(credentials, base_url='https://smba.trafficmanager.net/uk/')

# Create conversation
conversation = connector.conversations.create_conversation(reply_conversation_params)
# And send it
connector.conversations.send_to_conversation(conversation.id, activity_reply)

推荐阅读