4

I've read lots of docs on the Microsoft Web Site and here, but I couldn't find a solution for my case yet. Basically what I need is to consume a Microsoft Rest API (Graph?) to send a message notification(To a specific user) from an external app, using preferably NodeJS, Java or Python.

The closest I think I got was here:

I couldn't find the method send though. Also those docs are under beta version which there is a warning to not use it on production apps.

On the link below (Which is under 1.0 version), I can see the resource chatMessage(Preview) and the Method send, but when I click on it I get 404: https://learn.microsoft.com/en-us/graph/api/resources/teams-api-overview?view=graph-rest-1.0

My need is to send a one way communication (Not back and forth, no need of Bots), just a simple notification and that's it.

Is it possible to implement such a solution? Any reference that could help?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user3667143
  • 61
  • 1
  • 1
  • 4
  • if you landed here trying to figure out a way to send a message to a channel -> please check [that](https://stackoverflow.com/a/76904843/11968199) answer. – Maksym Kosenko Aug 15 '23 at 09:43

2 Answers2

0

Currently, only Bots can send 1:1 message to users.

Create chatMessage does not support application context so it has be an user sending the message. Also, you cannot create an new chat, you must use the list chats method to retrieve the Id of an existing chat before creating a chat message.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Wajeed Shaikh
  • 3,078
  • 1
  • 23
  • 30
  • Hi, thanks for your reply and I am sorry for my late reply. I am going on this direction at the moment then (Proactive Bots). My first step is to have a simple bot running on MS Teams just to exchange messages, I've created a Web App Bot on Azure and when I try to add this bot to Teams I am getting the  message error (Sending new messages to this bot has been disabled by your administrator.) The Administrator said he configured this already, so I am checking what could be (I am using a trial account to create the bot). – user3667143 Sep 24 '19 at 15:26
  • My second step will try to find a way to call the Bot from a HTTP request passing an user reference and then send the message directly to the user (Teams). I did some research but I didn't find a way to identify and send the message directly to the specific user (Team) without this user starting a conversation or without sending by the ID reference, any idea on this? Thanks. – user3667143 Sep 24 '19 at 15:30
  • In order to send Proactive message to any user, you need to know serviceUrl, tenantId and user's unique Id as documented in [Obtain necessary user information](https://learn.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bot-conversations/bots-conv-proactive#obtain-necessary-user-information) section. – Wajeed Shaikh Sep 26 '19 at 05:20
  • Great, I will have a look as soon as I come back to this project. Thanks – user3667143 Oct 03 '19 at 10:47
0

There are some code snippets at https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/conversation-basics?tabs=python

Send a message [Python]

To send a text message, specify the string you want to send as the activity. In the bot's activity handlers, use the turn context object's SendActivityAsync method to send a single message response. You can also use the object's SendActivitiesAsync method to send multiple responses at once. The code below shows an example of sending a message when someone is added to a conversation

async def on_members_added_activity(
    self, members_added: [ChannelAccount], turn_context: TurnContext
):
    for member in teams_members_added:
        await turn_context.send_activity(f"Welcome your new team member {member.id}")
    return
Nand0san
  • 473
  • 4
  • 13