python - 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 示例?
解决方案
我想通了,以防万一其他人试图做同样的事情并被卡住:
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)
推荐阅读
- drupal - 如何在 Drupal 6 中添加访问自定义 tpl 页面的用户权限?
- xquery - XQuery:返回后在循环中更新变量值
- r - 如何在 OpenCPU 中隐藏你的库代码
- windows - 在 Windows 上休息:有什么理由反对使用外部 openssl?
- angular - 角度路由器解析器 - 重新加载时从父级获取参数
- php - 将fastcgi_pass从网络套接字切换到unix套接字后,Laravel“由于不活动而导致页面过期”
- swift - Swift 4 从“执行”函数调用中获取布尔结果
- javascript - 如何用零填充数组中缺失的月份?
- reactjs - React Navigation:如何从堆栈返回另一个堆栈中的屏幕
- swift - 无法在 Mojave 上安装 jazzy