MS Teams: Invoking outgoing webhook from AdaptiveCard Actions - microsoft-teams

In Teams, I have setup outgoing webhooks to process messages with mentions to outgoing webhooks name.
Currently user is having to manually type in the mention to outgoing webhook (named OutgoingHookName) to post messages to it. I like to create an adapative card action in such a way that the outgoing webhook will be triggered when user performs the card action. I tried JSON as below, but the obviously incorrect/incomplete mention (<at>OutgoingHookName</at>) did not help.
Is it possible to trigger an outgoing webhook from with an adapative card action? If not, is there an alternative other than creating a full fledged messaging bot?
{
"type": "AdaptiveCard",
"version": "1.2",
"actions": [
{
"type": "Action.Submit",
"data": {
"msteams": {
"type": "imBack",
"value": "<at>OutgoingHookName</at> ID:1234"
}
},
"title": "Invoke Webhook"
}
]
}

Currently It's not possible to invoke an outgoing webhook from AdaptiveCard Actions and currently there is no work around for this. You must use #mention in compose message area for the webhook to receive message.
Microsoft will always focus on customer’s feedback and experience, some new features would be added to the services based on customers' feedback in the future, we also recommend you give your new idea in Teams UserVoice here if this needs to be consider as a future request.

Related

How can I turn my bot into a MS Teams app

I made a normal bot by using Microsoft Bot Framework and has deployed it to the Azure portal.
How can I possibly make it a Teams app other than channeling to Teams, for example, make it a Teams app package.
I checked some sample code on Github and noticed that general bots are a bit different from Teams bots, for example, general bots extend ActivityHandler but Teams bots extend TeamsActivityHandler. May I ask how can I turn my bot into a Teams app? Do I need to alter the code of the bot I made a lot?
Thanks
With a few exceptions, you don't really need to make changes to your bot code to deploy to Teams channel. However, I do think there are a few things you should be aware of and consider in your development. First of all, I'm going to assume you have or know how to turn on the channel from the Bot Service. Once you have done that, you can test your bot in Teams without even creating a Teams app by pasting the Microsoft App ID into the chat To: field (obviously it's not recommended to share this ID for general testing).
The main change you probably need is to remove mentions. These will mess with QnA Maker and/or LUIS as they are included in the query string. I have been doing this as the first step in the onMessage handler. My current bots use regex for this, e.g.
if (context._activity.text) ( // Make sure there is activity text before trying to replace
context._activity.text = context._activity.text.replace(/(#|<at>)((Bot Name)|(Teams App Manifest Name))(<\/at>)? ?/g, '');
}
However, I have also seen that the TurnContext object can do this via TurnContext.removeRecipientMention(context.activity); I've not actually tried that myself, though. If it works it would be very helpful in case you find yourself changing bot names as I have done in the past...
The other main change I made to my bots was creating Teams-specific adaptive cards with menu buttons. By default, Action.Submit will work for web channels but NOT Teams channel. A typical action would look like
{
"type": "ActionSet",
"actions": [
{
"type": "Action.Submit",
"title": "Get Order Status",
"data": "Get Order Status"
}
]
}
But Teams can't handle this and will error out on button click (at least when using standard Activity handler, not sure if it is the same if using TeamsActivityHandler.) Instead, you should check the channel before displaying cards with Action.Submit actions and display an alternative card instead. For example
if (context.activity.channelId == 'msteams') {
var welcomeCard = CardHelper.GetMenuCardTeams(welcomeMessage,'Y','Y');
} else {
var welcomeCard = CardHelper.GetMenuCard(welcomeMessage,'Y','Y');
}
And then your actions for Teams instead look like
{
"type": "ActionSet",
"actions": [
{
"type": "Action.Submit",
"title": "Get Order Status",
"data": {
"msteams": {
"type": "imBack",
"value": "Get Order Status"
}
}
}
]
}
I've tried combining these and it doesn't work well. You can add something to your handler to make Teams cards work in web, but the text will not be inserted into the chat like a typical button and it will instead be essentially like a backchannel event. I like this method much better.
Other than that you should be able to run your bot as-is, except for attachments as noted in your separate question. I have not gotten that to work and I believe it may be related to not using TeamsActivityHandler but I'm not sure.
Hopefully this helps. Go ahead and give it a try and you can create a new issue with any specific problems you face once the bot is operating in Teams.

Can you use slack buttons non-interactively?

While using Slack's block kit builder, I created a message that would send a notification as well as a link for the user to click on. I like the way the default button looks, but I get a warning whenever I click it saying my app isn't configured for interactivity.
The link does work, but the warning icon is unsettling. Is there a way to use these buttons without expecting interactivity? The alternative seems to be to just use a markdown link, but I don't think it looks as nice.
My block:
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Hello here's a notification"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<https://google.com|View Conversation>"
}
}
]
}
If I send this block straight from the block kit builder there's no warning message. I'm guessing this is because it gets sent as my user as opposed to an app.
As of now, there is no way to set up a block kit button without interactivity. i.e., when someone clicks on the button (with or without a URL), Slack sends a request to the preconfigured URL in your app config. The app needs to acknowledge this request and send an HTTP 200 OK response, in order for the button URL to work without the error sign.
You can read a rather detailed discussion on Slack's GitHub here.
A workaround, for now, would be to set up a webhook URL somewhere on the web (google cloud run could be a good free solution) which returns an acknowledge response. You can then alter your app's config to use this URL for app interactivity.
p.s. When you use block kit builder to send a preview message to Slack, it uses the same user token as the one used by Slack web app. The behavior you noted above can't be replicated when you use any other user token (received from an app's install flow).

How can a microsoft botframework bot mention a user in an adaptivecard?

Following the Schema explorer at adaptivecards.io, there is no schema available for a bot mentioning a user (and teams sending him the proper notification that he was mentioned afterwards).
See https://adaptivecards.io/explorer/ for reference.
We want to use the bot for proactive messages to our users. If a user gets mentioned in one other solution, we want to transfer that mentioning event to the teams channel conversation and leverage the ability of teams to notify the user appropriately.
Question: Is there a way to add a valid teams #mention to a channel member in a bot message using adaptivecards?
Mentioning users can be done in AdaptiveCards according to this documentation: https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format?tabs=adaptive-md%2Cconnector-html#mention-support-within-adaptive-cards
To include a mention in an Adaptive Card your app needs to include the following elements
<at>username</at> in the supported adaptive card elements
The mention object inside of an msteams property in the card content, which includes the Teams user id of the user being mentioned
The mention object looks similar to this:
{
"msteams": {
"entities": [{
"type": "mention",
"text": "<at>John Doe</at>",
"mentioned": {
"id": "8:orgid:{org-ID-of-the-user}",
"name": "John Doe"
}
}]
}
}
The ID to mention a user needs to be in this format: 8:orgid:{org-ID-of-the-user}

How to send a text message to a microsoft teams online meeting?

I am interested in doing the following with a csharp based teams bot:
Create an online meeting.
Invite several people into it.
Send a text message to this online meeting.
I am able to accomplish steps 1 and 2 with the graph communications api.
My bot can do many other tasks like (1) receive and reply to personal messages, (2) send proactive messages, (3) handle compose messaging extension invocations, (4) add the bot and send to groupchats, etc.
However, I have tried several approaches to step 3, and none have worked. I am getting this 403 Forbidden error when I try to send the message to the conversation:
{"error":{"code":"BotNotInConversationRoster","message":"The bot is not part of the conversation roster."}}
I have also reviewed this github thread:
https://github.com/microsoft/BotBuilder-Samples/issues/1772
I have tried adding the bot to the online meeting in a manner similar to adding the bot to a group chat, but the online meeting conversation does not appear in the search screen (when (1) going to the bot's info page from the 'Apps' menu, then (2) clicking 'Add to a chat', then (3) trying to find the conversation in the 'Select a chat to start using MyBot' search window that appears)
Add Bot to Chat
The request to send the message looks something like this:
POST https://smba.trafficmanager.net/amer/v3/conversations/19:meeting_XXXXXXXXXXXXXXXXXXXXXXXXXXXX#thread.v2/activities/f:2XXXXXXXXXXXXX
Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXX
Content-Type: application/json; charset=utf-8
{
"type": "message",
"serviceUrl": "https://smba.trafficmanager.net/amer/",
"channelId": "msteams",
"from": {
"id": "28:5fXXXXXXXXXXXXXXXXXXXXXX",
"name": "HelpDesk Bot"
},
"conversation": {
"id": "19:meeting_XXXXXXXXXXXXXXXXXXXXXXXXXXXX#thread.v2",
"tenantId": "XXXXXXXXXXXXXXXXXXXX"
},
"recipient": {
"id": "29:12XXXXX-XXXXXXX-XXXXXXXXXXXXXX",
"name": "SupportTest",
"aadObjectId": "XXXXXXXXXXXXXXXXXXXXXXX"
},
"text": "Welcome to the support session.",
"inputHint": "acceptingInput",
"attachments": [],
"entities": [],
"replyToId": "f:2XXXXXXXXXXXXX"
}
Am I doing something wrong?
Edit: added some more screen shots of menus available in the meeting chat room:
Online meeting menu
Compose menu
-Tom
Could you please try adding the bot from "Manage Apps" section under your meeting chat menu(the three dots next to the meeting chat title)?
You can then add the bot by choosing "upload a custom app" option from the bottom.

Azure VM monitoring default health criteria alert notification

New to Azure, Just wanted to understand if it possible to get a notification like email, slack message or a webhook push, when the default VM health criteria is breached (e.g. when Disk Avg. Disk sec/Read).
Below link says All health criteria are pre-configured to alert when the unhealthy condition is met.
https://learn.microsoft.com/en-us/azure/azure-monitor/insights/vminsights-health#alerting-and-alert-management
But how to configure the action group/ external notification.
I tried a solution mentioned in below link which tells to enable default notificationSettings, but no luck in getting the slack / email.
https://azure.microsoft.com/en-us/blog/understanding-health-criteria-in-azure-monitor-for-vms/
{
"nextLink": null,
"value": [
{
"etag": null,
"id": "/subscriptions/SUB_ID/resourcegroups/RG/providers/Microsoft.Compute/virtualMachines/SonarQube/providers/Microsoft.WorkloadMonitor/notificationSettings/default",
"name": "notificationSettings/default",
"properties": {
"actionGroupResourceIds": [
"/subscriptions/SUB_ID/resourceGroups/RG/providers/microsoft.insights/actionGroups/Webhook_gateway",
"/subscriptions/SUB_ID/resourceGroups/RG/providers/microsoft.insights/actionGroups/Slack%20Webhook",
"/subscriptions/SUB_ID/resourceGroups/RG/providers/microsoft.insights/actionGroups/VM%20monitoring"
]
},
"type": "Microsoft.WorkloadMonitor/virtualMachines/notificationSettings"
}
]
}
Classic metric alerts in Azure Monitor provide a way to get notified when one of your metrics cross a threshold.
Using this, you can send notifications to your email addresses as well as call a webhook when the alert fires.
Refer to these docs:
Create, view, and manage classic metric alerts using Azure Monitor
Have a classic metric alert notify a non-Azure system using a webhook

Resources