SOLVED

Send personal messages to Teams from daemon service.

%3CLINGO-SUB%20id%3D%22lingo-sub-3010279%22%20slang%3D%22en-US%22%3ESend%20personal%20messages%20to%20Teams%20from%20daemon%20service.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3010279%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%20I%20need%20to%20send%20notifications%20to%20my%20colleagues%20using%20Teams%20in%20case%20of%20emergency%20which%20is%20detected%20by%20monitoring%20system.%20These%20messages%20must%20be%20sent%20on%20behalf%20of%20background%20service%20which%20cannot%20follow%20interactive%20user%20authentication%20flow%20and%20therefore%20cannot%20get%20Authorization%20Code%20to%20authenticate%20on%20behalf%20of%20user.%3C%2FP%3E%3CP%3EI%20can%20connect%20to%20Azure%20AD%20using%20Graph%20SDK%20for%20Golang%20and%20get%20all%20users%20of%20my%20organization.%20But%20I%20cannot%20use%20Chat%20API%20because%20it's%20not%20allowed%20in%20%22application%20only%20context%22.%3C%2FP%3E%3CP%3EIs%20there%20a%20way%20to%20send%20personal%20user%20messages%20from%20daemon%20service%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3010279%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAuthentication%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ETeams%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3021800%22%20slang%3D%22en-US%22%3ERe%3A%20Send%20personal%20messages%20to%20Teams%20from%20daemon%20service.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3021800%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1231076%22%20target%3D%22_blank%22%3E%40DVTitov%3C%2FA%3E%26nbsp%3B-%3CSPAN%3EWe%20are%20looking%20into%20this%20I%20will%20get%20back%20to%20you%20soon.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Hello, I need to send notifications to my colleagues using Teams in case of emergency which is detected by monitoring system. These messages must be sent on behalf of background service which cannot follow interactive user authentication flow and therefore cannot get Authorization Code to authenticate on behalf of user.

I can connect to Azure AD using Graph SDK for Golang and get all users of my organization. But I cannot use Chat API because it's not allowed in "application only context".

Is there a way to send personal user messages from daemon service?

6 Replies

@DVTitov -We are looking into this I will get back to you soon.

@DVTitov - You can send a personal messages to different users in Teams with daemon service but you will need to store their information like Service URL, conversation id in storage while installing the bot.

You can do it like below:

var conversationReference = new ConversationReference
{
ServiceUrl = serviceUrl,
Conversation = new ConversationAccount
{
Id = conversationId,
},
};



await this.botAdapter.ContinueConversationAsync(
botAppId: this.microsoftAppId,
reference: conversationReference,
callback: async (turnContext, cancellationToken) =>
{
// Send message.
var activityResponse = await policy.ExecuteAsync(async () => await turnContext.SendActivityAsync(message));
return response;
}

Reference link:
BotAdapter.ContinueConversationAsync Method (Microsoft.Bot.Builder) | Microsoft Docs

Hi!
I'm not sure this is my case. I don't have a bot. I need to develop Linux daemon service that should propagate infrastructure monitoring alerts to system admins. I use Golang SDK and I'm able to query all users of my organization from Azure AD (Microsoft Graph API). Now I need a REST or Go SDK method to send message to Teams user referenced by their AD UPN.
Me daemon service is by no means a bot or web app. Imagine it's a plugin for Zabbix or MS SCOM.
Hi!

Example for Go behind that link is outdated, but anyway I cannot use chat API in applications only context.
My application gets Auth token using application secret obtained at Azure. I don't have any user logged in so I can't get Authorization Code.
Hence when I call chat API I get an error: "Chat API not allowed in application only context" (or similar).
best response confirmed by DVTitov (New Contributor)
Solution

@DVTitov - We got a confirmation from engineering team that
"To post as a background service, the user must use a bot."

So currently we do not have any way to send the direct message to user using Graph API.

Thanks, 

Chetan Sharma

----------------------------------------------------------------------------------------

If the response is helpful, please click "**Mark as Best Response**" and like it. You can share your feedback via Microsoft Teams Developer Feedback link. Click here to escalate.