First off, I'm new to Microsoft Teams (and the larger office/365/azure ecosystem), and have been a bit overwhelmed at the complexity needed to perform what seemed like a simple action. I have a webapp that integrates with apps like Slack to send individual reminders to users. We prefer individual "one-to-one" messages over spamming a whole team, because we only want to remind users that need reminding, and we want to include a link they can click that is specific to that user.
I've been tasked with making this same idea work in MS Teams. I've created an Azure App, and added a bot, and I can freely hit endpoints on the Microsoft Graph API, but I haven't found the right incantation to create a chat and send a message from my bot to a User via Graph. So now I'm trying to use the botframework, but with the hopes of boiling it down to a series of REST API calls, and not to require an always on bot running in the cloud somewhere. We have no plans for the user to message the bot, or for the bot to reply to the user in any way. Instead, I just have a cron job that will wake up, generate a list of users and links needed to be sent, and then send them. I want to be able to send my messages to Teams users in that moment, and detect any errors as each message is sent.
I've found that with what Microsoft calls a "serviceUrl", I can POST to {surviceUrl}/v3/conversations
to create a chat, and then POST to {surviceUrl}/v3/conversations/{chatId}/activities
to send a message. The problem is that I can't figure out how to get the correct serviceUrl automatically. By hard coding https://smba.trafficmanager.net/amer/
, I can get it to work for a test tenant, but I'm led to believe that the serviceUrl is different for different tenants, and MS reserves the right to change them at any time.
So how do I get the correct serviceUrl? Or am I barking up the wrong tree, and I need to take a different approach?
Thanks @Sayali-MSFT for the answer, which is this:
In scenarios where you're not using bot frameworks and not dealing with real-time interactions (i.e., receiving messages and responding), obtaining the turnContext.Activity.* is not necessarily required. If your goal is purely to send messages at scheduled intervals, you can proceed with the REST API calls as you've indicated. Use the endpoint smba.trafficmanager.net/teams/v3/conversations to create or retrieve the chatId for users.