Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

  1. An user installs my third-party MS teams bot, adding it to one of their Teams channels.
  2. My Bot needs to send ad-hoc messages as part of an event from an unrelated back-end system.

The botframework does not let you message channels at will, it needs a conversation reference. 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.

Reading the documentation

The documentation will have you believe that it is in fact possible to send message at will, using the following steps:

  1. Get the user ID or team/channel ID (if needed).
  2. Create the conversation or conversation thread (if needed).
  3. Get the conversation ID.
  4. Send the message.

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?

For step 2, how do I create a conversation if I don't know what team channels there are?

Conclusion

Does someone know how to send a message to a MS Teams channel using a Python app/bot? 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.

like image 896
sf033 Avatar asked Dec 05 '25 10:12

sf033


1 Answers

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. 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

like image 104
Hilton Giesenow Avatar answered Dec 07 '25 01:12

Hilton Giesenow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!