Integrating Microsoft team into my web app - microsoft-teams

I have a web app where if a user signs up, a notification is sent to the slack channel. I want to achieve the same thing in Microsoft team but I cant find any good resources. When a new user signs up, a message will be posted into the microsoft team group.Will it be possible to do this?

This can be easily achieved in Microsoft Teams using Connectors.
Here are the steps to post data to any channel:
In Microsoft Teams, choose the More options (⋯) button next to the
channel name in the list of channels and then choose Connectors.
Add an Incoming webhook and copy the webhook URL.
You can post Message Card given below to this URL using
Postman/Fiddler/Code.
{
"summary": "Alert!",
"themeColor": "0078D7",
"sections": [
{
"activityTitle": "Web app event",
"text": "Something happened in the web app!"
}],
"potentialAction": [
{
"#type": "OpenUri",
"name": "View event",
"targets": [
{ "os": "default", "uri": "http://mywebapp.com/path/to/event" }]
}]
}
You can also Build your own Connector with custom configurations.

Related

Teams file consent card not sending "accept" activity to bot handler while implementing Teams Bot API , it is showing went wrong

We have a Teams bot installed for internal company use and it is capable of sending files to our users. Our application that handles the bot does not receive the file consent allow activity but decline activity is working fine , as said in the documentation we have implemented it .
will you pls help me out with the issue .
I'm using the proper documentation of Microsoft teams passing these values but not getting the result.
attachments": [{
"contentType": "application/vnd.microsoft.teams.card.file.consent",
"name": "result.txt",
"content": {
"description": "Text recognized from image",
"sizeInBytes": 4348,
"acceptContext": {
"resultId": "1a1e318d-8496-471b-9612-720ee4b1b592"
},
"declineContext": {
"resultId": "1a1e318d-8496-471b-9612-720ee4b1b592"
}
}
}]

Adaptive card sends error message when using ToggleVisibility action in MS Teams desktop app

This morning we started getting the standard bot error message in MS teams desktop client when using a card with toggleVisbility actions. Selecting the button to toggle visbility on part of the card results in the below error, even though the toggle works as expected!
bot error message
The adaptive card code looks something like this:
{
"type": "ActionSet",
"actions": [
{
"type": "Action.ToggleVisibility",
"title": "Alerts",
"targetElements": [
"Incidents",
{
"elementId": "Metrics",
"isVisible": false
},
{
"elementId": "Admin",
"isVisible": false
}
]
},
{
"type": "Action.ToggleVisibility",
"title": "Actions",
"targetElements": [
"ActionButton"
]
}
]
}
This message would be expected if the bot app doesn't respond to a message/action, however the toggle action shouldn't be sending any data to the bot applicaiton. I confirmed this in the teams web client using the network tracing dev tool. When selecting the toggle action no new network calls are made.
We are not seeing this error in either the web client or the mobile client, only in Teams Desktop app.
This bot has been running for months without this issue and we didn't change the code, which makes me believe this is a MS teams side bug that was recently introduced.
Also: This same issue was independently identified in the Adaptive Cards Project.
https://github.com/microsoft/AdaptiveCards/issues/8145

Dynamic typeahead in Adaptive Card Task flow

I'm trying to implement the dynamic typeahead search as was shown on the below resources:
https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/dynamic-search?tabs=desktop%2Ccsharp
https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-type-ahead-search-adaptive-cards/csharp
I'm having the following Adaptive Card returned from the OnTeamsMessagingExtensionFetchTaskAsync (from message action):
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.5",
"body": [
{
"id": "choiceSelect",
"type": "Input.ChoiceSet",
"choices": [
{
"title": "Choice 1",
"value": "Choice 1"
},
{
"title": "Choice 2",
"value": "Choice 2"
}
],
"placeholder": "Placeholder text",
"style": "filtered",
"choices.data": {
"type": "Data.Query",
"dataset": "cases"
}
}
]
}
Card is rendered correctly, but when I start typing, I'm getting the following results:
No request is being made. I was trying to debug the JS, but it is troublesome for me - I couldn't pinpoint the exact place it fails, but got these symbols to lookup: executeSearchInvoke, enableAppPermissionEnforcement and enableTenantSettingsForBots in 3.2-app.min.js.
Can anyone point me in the right direction? Is there some kind of dependency or permission I should add to the bot? Some setting in Teams Admin Center? I can add that static typeahead works flawlessly, but I need the dynamic one (big data collection to query).
EDIT:
I have confirmed that the app is added to the team (it is visible on the list of apps in team settings); I've removed and added it again just in case. I am still getting the same results.
List of permissions visible from the App details page:
This app will have permission to:
Receive messages and data that I provide to it.
Send me messages and notifications.
Access my profile information such as my name, email address, company name, and preferred language.
Receive messages and data that team members provide to it in a channel.
Send messages and notifications in a channel.
Access this team's information such as team name, channel list and roster (including team member's names and email addresses) - and use this to contact them​.

How to get team id when the bot is installed in personal scope(MS Teams)?

I have a use case where I need to show following information in my personal application.
List of channels in teams where bot is installed.
List of users in teams where bot is installed.
I was exploring connector client for the same and came up with following code:-
const credentials = new MicrosoftAppCredentials(appId, appPassword);
const connectorClient = new ConnectorClient(credentials, {
baseUri: serviceUrl
});
const token = await credentials.getToken();
axios.defaults.headers.common.Authorization = `Bearer ${ token }`;
# To get channels
const response = await axios.get(
'https://smba.trafficmanager.net/in/v3/teams/{teamId}/conversations'
);
# To get members
const users = await connectorClient.conversations.getConversationPagedMembers(teamId);
This works perfect as long as I have the teamId.
But the issue I am facing here is with respect to finding teamId in personal scope. I install my bot application as follows by choosing the Add option.
As far as I understand, the above installs the bot in the personal scope of the user. Now, in this scenario the team id information is not present in conversationUpdate event at all. Please note that this is the first time I am installing the bot in the team, so the data should be available as per Microsoft documentation, but the only information available in channel object is tenant.
{
"membersAdded": [
{
"id": "28:f5d48856-5b42-41a0-8c3a-c5f944b679b0"
}
],
"type": "conversationUpdate",
"timestamp": "2017-02-23T19:38:35.312Z",
"localTimestamp": "2017-02-23T12:38:35.312-07:00",
"id": "f:5f85c2ad",
"channelId": "msteams",
"serviceUrl": "https://smba.trafficmanager.net/amer-client-ss.msg/",
"from": {
"id": "29:1I9Is_Sx0OIy2rQ7Xz1lcaPKlO9eqmBRTBuW6XzkFtcjqxTjPaCMij8BVMdBcL9L_RwWNJyAHFQb0TRzXgyQvA"
},
"conversation": {
"isGroup": true,
"conversationType": "channel",
"id": "19:efa9296d959346209fea44151c742e73#thread.skype"
},
"recipient": {
"id": "28:f5d48856-5b42-41a0-8c3a-c5f944b679b0",
"name": "SongsuggesterBot"
},
"channelData": {
// for me this object is empty
"team": {
"id": "19:efa9296d959346209fea44151c742e73#thread.skype"
},
"eventType": "teamMemberAdded",
"tenant": {
"id": "72f988bf-86f1-41af-91ab-2d7cd011db47"
}
}
}
Next, I also tried to install the bot in the team scope by using Add To Teams option. In this case it prompts me to select a channel to install, in which I choose general.
Now, I do get the team object inside channelData in onConversationUpdate and this flow works perfectly fine.
{
"membersAdded": [
{
"id": "28:64564f44-dd7c-441a-b427-efcd662f21b5"
}
],
"type": "conversationUpdate",
"timestamp": "2021-10-14T13:22:01.6072361Z",
"id": "f:4ebc9a41-5140-7621-33f5-31d97275ce00",
"channelId": "msteams",
"serviceUrl": "https://smba.trafficmanager.net/in/",
"from": {
"id": "29:17ZGff4Pvqz_zSNqEexg-86uBFcB6vnOBZzCwu4_puGdDsrYWCW_DdlB15PrcjC--nLlqD5CwtLMJyzXPY5OSsg",
"aadObjectId": "eac26e98-104a-4785-87aa-bcf77ea1d7c1"
},
"conversation": {
"isGroup": true,
"conversationType": "channel",
"tenantId": "c8fef0de-e240-4456-b523-3285ecc62087",
"id": "19:y7qDBfGH2jE_Ze6G8mJS_CiWiqCaRFfH77jFZvJ1xgU1#thread.tacv2"
},
"recipient": {
"id": "28:64564f44-dd7c-441a-b427-efcd662f21b5",
"name": "Trick"
},
"channelData": {
"team": {
"aadGroupId": "5bc77aa9-9487-49ae-958f-b37b2191e64d",
"name": "test 5",
"id": "19:y7qDBfGH2jE_Ze6G8mJS_CiWiqCaRFfH77jFZvJ1xgU1#thread.tacv2"
},
"eventType": "teamMemberAdded",
"tenant": {
"id": "c8fef0de-e240-4456-b523-3285ecc62087"
}
}
}
So what I am trying to understand here is that, why is the information not coming in case the bot is installed in personal scope?
I am asking this mainly because without personal scope added for bot(i.e if I keep scope only as team), the application does not show for user, inside Apps. But if I allow the scope to be extended to personal the user might select that while installing the application and my teamId information will not be available to fetch the data, that I need.
This brings to my next question, which is, is there any way in which the default add button on the add app screen installs the bot in such a way that I get team object inside channelData, in conversationUpdate in every scenario, i.e whether I choose add or add to team?
Is this how it is supposed to behave or am I missing something. Would love to hear some thoughts on this. Thanks in advance.
It might be that you're over thinking this - here's a more simple view:
if you install a bot into a Team, you'll get a Team Id (and any related channel where it is installed).
if you have "personal" scope set up for the bot, then the user also has the option to install the bot into "personal" scope. As this implies, they are NOT installing the bot INTO an actual Team - that's why you're not receiving a Team Id. It's not broken - it's entirely correct.
If you don't WANT your bot to be able to be installed in personal scope, simply remove that option in your manifest (the "personal" scope) - you have the ability to choose because it depends what you're wanting the user to be able to do with your bot. Some bots only make sense inside a Team, others only in Personal Scope, others only in Group Chat or in a Meeting - you can allow your bot to installed in any/all of these are relevant.

Bot is not responding to #Mention when sending message using Graph API

I have created and deployed a bot in Microsoft Teams. Bot Works properly and responds when user talks to the bot using #Mention (e.g. #mybot) in a channel. I just tried to send message to the bot using graph API call:
https://graph.microsoft.com/beta/teams/{group-id-for-teams}/channels/{channel-id}/messages
Method: POST
Content-type: application/json
Body:
"body": {
"contentType": "html",
"content": "Hello World <at id=\"0\">standupbot</at>"
},
"mentions": [
{
"id": 0,
"mentionText": "StandupBot",
"mentioned": {
"application": {
"id": "[my-bot-id]",
"displayName": "StandupBot",
"applicationIdentityType": "bot"
}
}
}
]
}
The Post request goes well, message is posted in my team and bot gets mentioned. But bot is not responding to the mention. However, if user manually mentions the bot in team then bot responds.
What is wrong here, Am i missing something or is it a bug? Please guide.
P.S: I am using Graph Explorer.

Resources