Getting Skype to Post to a Group Conversation Via a Conversation ID - botframework

Hello Bot Framework engineers! I'll be honest here and mention straight off I'm not a developer, but I'm attempting to get my Skype Bot to work in Azure, and I've gotten most of the way there. The only thing I'd like to know at this point is how to get a ConversationID so I can send messages THROUGH the Skype bot to a group that the bot is a part of. Is that possible to get somehow?

You can get the skype conversation ID through the message. Using Ngrok, I found one which looked something like:
"conversation": {
"isGroup": true,
"id": "19:8cc9a9nnnnnnnnnnnnnnnnnnnnnnnnnn#thread.skype"
},
C# it would be something like:
turnContext.Activity.Conversation.Id

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 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!

Programmatically sending a message to a bot in Microsoft Teams

I have created a proactive bot that basically asks certain questions to a user when a user starts conversation with the bot. The bot is deployed in Microsoft Teams environment. Is there any way that i can send automated message to a bot in a channel? I know messages can be sent using powershell by utilizing webhook url exposed by a particular team or using MS Flow. But I want to mention bot (e.g. #mybothandle) in the message so the bot starts asking questions by itself than requiring the user to start the conversation (by mentioning the bot manually) but not finding the way to mention.
Your suggestions are welcome.
Basically you want to message the user directly at a specific point in time (like 24 hours later). I'm doing this in a few different bots, so it's definitely possible. The link that Wajeed has sent in the comment to your question is exactly what you need - when the user interacts with your bot, you need to save important information like the conversation id, conversation type, service url, and To and From info. You can store this, for instance, in a database, and then you can actually have a totally separate application make the call AS IF IT WAS your bot. In my bots, for example, I have the bot hosted in a normal host (e.g. Azure Website) but then have an Azure Function that sends the messages, for example, 24 hours later. It just appears to the user as if it was a message from the bot, like normal.
You will also need the Microsoft App ID and App Password for your bot, which you should have already (if not, it's in the Azure portal).
In your "sending" application, you're going to need to create an instance of Microsoft. Bot.Connector.ConnectorClient, like follows:
var Connector = new ConnectorClient(serviceUrl, microsoftAppId: credentialProvider.AppId, microsoftAppPassword: credentialProvider.Password);
You also need to "trust" the service url you're calling, like this:
MicrosoftAppCredentials.TrustServiceUrl(serviceURL);
Then you create an instance of Microsoft.Bot.Schema.Activity, set the required properties, and send it via the connector you created:
var activity = Activity.CreateMessageActivity();
activity.From = new ChannelAccount([FromId], [FromName];
activity.Recipient = new ChannelAccount([ToId], [ToName]);
activity.Conversation = new ConversationAccount(false, [ConversationType], [ConversationId]);
activity.Conversation.Id = [ConversationId];
activity.Text = "whatever you want to send from the bot...";
Connector.Conversations.SendToConversationAsync((activity as Activity)).Wait();
All the items in square braces are what you get from the initial conversation the user is having with the bot, except that the From and To are switched around (when the user sends your bot a message, the user is the FROM and your Bot is the TO, and when the bot is sending you switch them around.
Hope that helps
To all Future Visitors, Microsoft Graph API (Beta) now provides a way to send message and mention the bot/user using following endpoint:
https://graph.microsoft.com/beta/teams/{group-id-for-teams}/channels/{channel-id}/messages
Method: POST
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"
}
}
}
]
}
However, there is a bug that bot doesn't respond when receives the message:
Bot is not responding to #Mention when sending message using Graph API

Bot Framework ErrorResponseException: "The bot referenced by the 'from' field is unrecognized"

My bot in Telegram worked fine for many months, and suddenly...
ErrorResponseException: "The bot referenced by the 'from' field is unrecognized"
It throws each time when my bot tries to reply to an incoming message.
The from field didn't change. The bot id in Telegram can't change.
I checked: the bot HTTP Request is sent with the correct bot id in the from.id field.
I use Microsoft.Bot.Builder v3.15.3 Nuget package
I had to renew the Telegram Bot access token
I went to #BotFather in Telegram and invoked the /revoke command to change the token to access HTTP API.
Then I went to my Functions bot in the Azure Portal, and on Channels section clicked on "Edit" on my Telegram bot. I pasted the new Access token, saved, and it works again!
What caused it?
Looks like the token somehow expired. I created my bot 355 days ago (Dec 14, 2017), and haven't changed the token since then.
But I'm not sure if it's the reason.
See how similar solution helped for Facebook bot.
I faced with the same issue for the Skype for Business channel. I haven't changed the from.id but the bot stoped to work correct. I seems Microsoft started to validate this field and before I had incorrect value of this one.
I just went throught the documentation (https://learn.microsoft.com/en-us/skype-sdk/skype-for-business-bot-framework/docs/overview) one more time and saw my mistake:
"from": {
"id": "sip:user#contoso.com",
"name": "Contoso User"
}

Persistent Skype user ID across individual and group chat.

When a bot chat with a user individually or in a group, the API returns different user ids. How can I know it's the same person?
Skype user's information fields looks like the following "from": { "id": "29:1DwlGVzj.....", "name": "My Skype Name" } (and bot's id is "28:appId").
This user id is a specific to your bot, it is a hash but the way it is generated is not known (not open-source). But this id is identidical for a unique user when talking individually with the bot or inside a group conversation with the same bot.
See sample here, I just checked:
Direct message between user and bot:
Group conversation including same user and same bot:
I've hidden some characters of the id in case of... but I confirm they are exactly the same values.
See also questions around the same problems:
For more details about the different channels and the ID format: Authenticate user across channels in Microsoft bot Framework
Get Skype ID from Activity object Bot Framework V3
Getting Skype Identity In Bot Framework?

Resources