Can you use slack buttons non-interactively? - slack

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

Related

Teams Toolkit HelloWorld chat bot - Failed to send

I’ve just downloaded Teams Toolkit onto VSCode and used the plugin to create a Command Bot project. Completed all the prerequisites and configurations on my tenant (I’m the admin for our 365 business account)
Everything installs great.
I hit f5 to launch the debugger.
All prerequisite checks pass.
Chrome opens
I can [Add] my local debug bot into the web app version of teams
I go to send any message OR the helloWorld command that comes with the template app and it gives me “Failed to send message” error.
When I hit F12 to bring up the Chrome dev tools and go into the network tab to see the call that is being sent, I see and Error as the response payload: errorCode 201 errorSubCode 1 with the message “One or more of the user ids provided are not valid."
Payload:
{
"members": [
{
"id": "8:orgid:xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"role": "Admin"
},
{
"id": "28:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"role": "Admin"
}
],
"properties": {
"threadType": "chat",
"chatFilesIndexId": "2",
"uniquerosterthread": "true",
"fixedRoster": "true"
}
}
Response
{
"errorCode": 201,
"message": "One or more of the user ids provided are not valid.",
"standardizedError": {
"errorCode": 201,
"errorSubCode": 1,
"errorDescription": "One or more of the user ids provided are not valid."
}
}
I haven’t written any custom code or made any changes. Just trying to launch the bot straight from Toolkit creation.
I've also tested the ngrok session that is connected to make sure that communication back to me is working fine. I see logging when I try to hit the ngrok url so I feel this is a failure at the point of Teams trying to send to their API.
I’ve followed all the steps in the documentation regarding setup. I would appreciate any help anyone would have on this.
Thank you
This is probably caused by incorrectly bot identity used in Teams channel registration in Bot Framework. Not quite sure what happen when calling the bot framework service to do the bot registration herre.
You can check if your App ID and password is correctly in Bot Framework registration:
The bot credentials in .fx configs:
The app password can be decrypted from local.userdata
To resolve this, could you please try one of the following solutions:
Create a new Command Bot and run F5 again.
Or, you can delete the local.userdata and state.local.json files in your current project. And then re-run F5, the toolkit should create a new AAD app for your bot registration in this case.

MS Teams: Invoking outgoing webhook from AdaptiveCard Actions

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.

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.

A week old MS Teams invoke action button results in Invalid teamId and/or appId specified message

I'm developing a Teams bot app that generates a thumbnail card (application/vnd.microsoft.card.thumbnail) via unfurl or search extension. This card contains 3 buttons from which one of them invokes a task. Everything was working as expected for a while but then I noticed that if I click on that button on a card that's been posted more than a week ago, nothing happens, my server does not receive any request from MS Teams. Actually in the Teams web app you can see an error log in the JS console saying:
AppsService: getInstalledAppForTeam - Invalid teamId and/or appId
specified
If I post a new card from the same app (same app version without updating it), the button works again, but only for a week or so.
This is the JSON definition of that invoke button I use:
{
"type": "invoke",
"title": "Invoke task",
"value": {
"type": "task/fetch",
"someObjectId": "123",
"command": "myCommand"
}
}
Not sure if I miss anything there but according to doc it does not seem like that.
Is there some defined period after which the invoke buttons are "retired"?
The app is installed via Teams Admin Center https://learn.microsoft.com/en-us/microsoftteams/manage-apps
I've not looked into this scenario, so I can't say 100% for sure what's going on, but what I suspect is this: Your App Id/App Password are important because they're being used to secure the payload in some way, and that process might have a time limit to ensure stale messages aren't resent (i.e. replayed by an invalid party), or something like that. As a result, it's not that the app id is per se expired, but rather that the message somehow is. Again, just a theory...

Can Botframework add a reaction to a user message?

Can bot add a reaction to a user message?
I tried to send an activity like this:
{
"type": "messageReaction",
"reactionsAdded": [{ "type": "like" }],
"replyToId": 1579278444192
}
on this URL - /v3/conversations/{conversationId}/activities/{activityId}
It depends entirely on the channel you are wanting to implement this on. If channel x (Facebook, Slack, etc.) sends "reactions" as part of the activity and the service allows you to scope to it, then it is possible to return bot responses based on those.
The Botbuilder-Samples GitHub 25.message-reaction Javascript sample demonstrates how this is achieved for Teams. The C# version can be referenced here. You would need to adjust the code to look for the appropriate context/activity data points and filter on those to send a response back.
Hope of help!

Resources