[英]How to proactively send a message to a teams channel
I can't seem to figure out how to proactively message a MS teams channel using a Python Bot (botframework).我似乎无法弄清楚如何使用 Python Bot(机器人框架)主动向 MS 团队频道发送消息。
The botframework does not let you message channels at will, it needs a conversation reference. botframework 不会让你随意留言频道,它需要一个对话参考。 You can get a conversation reference in various ways, such as someone messaging the bot, or fetching the list of channels and constructing a
conversationId
from that.您可以通过多种方式获取对话参考,例如某人向机器人发送消息,或获取频道列表并从中构造一个
conversationId
。
The documentation will have you believe that it is in fact possible to send message at will, using the following steps: 该文档将使您相信实际上可以使用以下步骤随意发送消息:
For step 1, how/when do I get the channel ID if there are no events that my Bot has been added to a channel?对于第 1 步,如果没有我的机器人已添加到频道的事件,我如何/何时获取频道 ID?
For step 2, how do I create a conversation if I don't know what team channels there are?对于第 2 步,如果我不知道有哪些团队频道,如何创建对话?
Does someone know how to send a message to a MS Teams channel using a Python app/bot?有人知道如何使用 Python 应用程序/机器人向 MS Teams 频道发送消息吗? It should not require user interaction .
它不应该需要用户交互。 The app/bot gets added to a Teams channel, and it should immediately post a message inside this channel .
应用程序/机器人被添加到 Teams 频道,它应该立即在此频道中发布一条消息。
Turns out the issue was that my on_teams_members_added()
was not getting called because I kept deleting the app within Teams instead of uninstalling.原来问题是我的
on_teams_members_added()
没有被调用,因为我一直在 Teams 中删除应用程序而不是卸载。
Make sure to:确保:
With this code you can send a channel message when the Bot enters the channel:使用此代码,您可以在 Bot 进入频道时发送频道消息:
async def on_teams_members_added( # pylint: disable=unused-argument
self,
teams_members_added: [TeamsChannelAccount],
team_info: TeamInfo,
turn_context: TurnContext,
):
for member in teams_members_added:
if member.id == turn_context.activity.recipient.id and team_info is not None:
# bot entered a Teams channel
await turn_context.send_activity("Hello channel! I have just been added.")
Your handler needs to inherit from TeamsActivityHandler
.您的处理程序需要从
TeamsActivityHandler
继承。
I'm working on a sample for the pnp Teams samples repo on GitHub that I'm hoping to submit in the next few days.我正在为 GitHub 上的 pnp Teams 示例存储库制作一个示例,我希望在接下来的几天内提交该示例。 I haven't started on the documentation yet, but the code is fully functional, with both a C# and a Node.js version of the backend, which sends a -very- simple proactive message example (showing the most basic things you need) - hopefully it can be of use even though it's not in Python - see https://github.com/HiltonGiesenow/teams-dev-samples/tree/add-proactive-messaging-sample/samples/bot-proactive-messaging/src
我还没有开始编写文档,但是代码功能齐全,有 C# 和 Node.js 版本的后端,它发送一个非常简单的主动消息示例(显示您需要的最基本的东西)-希望即使它不在 Python 中,它也可以使用 - 请参阅https://github.com/HiltonGisenow/teams-dev-samples/tree/add-proactive-messaging-sample/samples/bot-proactive-messaging/src
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.