Simulating skype for business development environment in Microsoft BotFramework WebChat - botframework

I’m working with Microsoft bot framework (Node js) on a project with a multi chatbot approach.
After Registering the bot with the Microsoft Bot Framework, adding multiple Skype for Business channels and registering the bot to a Skype for Business different tenants(replaced by the Name parameter with the bot display name and with unique users accounts from their domain), I’m trying to identify the bot from the "bot" object inside the session message coming from SFB that will help me to detect the user domain and ensure that user is receiving the correct answers depending on his domain
When testing this approach with the emulator I’m always receiving the same bot object.
So, I’m trying to modify the BotFramework WebChat Emulator source code to emulate SFB and set the SFB dev environment with a new textbox by putting the generated sip of the chatbot in the session to test my solution.
I’m asking if there is a way to simulate SFB inside the Microsoft BotFramework WebChat Emulator?
Thank you in advance!

The Bot Framework Emulator cannot simulate Skype for Business because:
The emulator has a built in Connector Service that is modeled more after the Direct Line channel's connector service. The behavior of this service will not exactly match the behavior of the Skype for Business connector service.
The emulator uses Web Chat as the UI client. Skype for Business has various clients, and none of them will render activities the same way Web Chat does. Skype for Business clients do not support the same message types (Cards, buttons, etc).
If you are using the v4 emulator, you can modify your .bot file and provide whatever bot id you like:
{
"name": "TestBot",
"description": "",
"services": [
{
"type": "endpoint",
"appId": "",
"appPassword": "",
"endpoint": "http://localhost:3979/api/messages",
"id": "sip:testfakebotid",
"name": "http://localhost:3979/api/messages"
}
],
"padlock": "",
"version": "2.0",
"overrides": null,
"path": "C:\\BotFiles\\TestBot.bot"
}
This id will then be sent to the bot in every message, as the activity.Recipient.id:

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.

Hide some input messages to MS teams bot

I am building a bot that takes some sensitive inputs. As I would like to add this bot to an MS team/group, how do I hide/mask user's input to the bot from other users. Is that possible?
Currently it's not possible to send masking data to bot from compose message area. Instead you can use adaptive card to send masking data to bot.
{
"type": "Input.Text",
"id": "secretThing",
"style": "password"
}
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.

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

Send Attachments to Bot in Teams

I'm working with BotBuilder in .NET C#.
I can't figure out how I can send an attachment to the bot using Teams client - I've tried using the Windows desktop app and the web client but neither shows an attachment button in a chat with the bot.
I also tried with the Android client and found that I could send image attachments but not other file types, which I then went back and found that I could do the same in desktop/web clients by pasting the image into the chat box.
Using this method I do get an item in Activity.Attachments with ContentType="image/*". Any other type of file that I try to attach in the Android client is not sent to the bot (nothing in the Activity.Attachments collection) and as I said the other clients won't allow me to even attach anything in 1:1 chat.
Attaching a file in a Teams Channel adds the file to the Channel but I don't get any reference to the attachment if I #mention the bot along with the attachment.
The only mention of consuming attachments in bot sent via Teams I can find is here where it's stated that you'll need to use a JwtToken to access the file. I'm guessing this is currently a limitation in Teams as I'm able to send/receive attachments from other channels, but I'd like to confirm that there isn't some nuance that I'm missing.
Currently, Microsoft Teams does not support the ability to send non-image files to bots.
We are currently working on delivering this feature, but we do not yet have an ETA.
Image attachment can be send through Teams by copy pasting them in the Chat window.Teams have pushed the new Build where you can have Attachment Functionality available in Chat BOT. Now you can attach any file in the teams channel but you need to continue to send the Jwt token.
You can explore the type FileDownloadInfo which can be used to know the file type, content and other required details after you send the attachment to the BOT.
To answer your first question. Microsoft Teams does not show "attachment" button by default. You can install "App Studio" in Teams, and create an app for your bot, specify your app allows upload attachments. And install it in your own Team account for testing.
The second question, you can't get the image attachment. The JSON from Microsoft Teams channel is different from other channels.
You may notice the "contentType" is different, and the "contentUrl" requires a login in order to download the image. You need to use "content.downloadUrl" instead.
"attachments": [
{
"contentType": "application/vnd.microsoft.teams.file.download.info",
"contentUrl": "https://xxx-xxx.sharepoint.com/personal/xxxx/Documents/Microsoft Teams Chat Files/Cloud section in Singapore.PNG",
"content": {
"downloadUrl": "https://xxxx-xx.sharepoint.com/personal/xxxx/_layouts/15/download.aspx?UniqueId=a3cf2177-1cc7-433b-8344-129140c0694e&Translate=false&tempauth=eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAvc2FnZTM2NS1teS5zaGFyZXBvaW50LmNvbUAzZTMyZGQ3Yy00MWY2LTQ5MmQtYTFhMy1jNThlYjAyY2Y0ZjgiLCJpc3MiOiIwMDAwMDAwMy0wMDAwLTxxxxx&ApiVersion=2.0",
"uniqueId": "xxxx-1cc7-433b-8344-xxxxxx",
"fileType": "png"
},
"name": "Cloud section in Singapore.PNG",
"thumbnailUrl": null
}
]

Sending messages in Teams with a bot on behalf of a user

I have an app containing a bot on Microsoft Teams, built using the bot-framework. I need my application to be able to let users send message to a specific channel and thread. I can do this with my bot using the "proactive messaging" ability, but the message is then send by the bot, not the user.
Is there any way to achieve this as if the user sent the message?
You don't need to use the bot.
Just try this Microsoft Graph API endpoint (beta version):
POST https://graph.microsoft.com/beta/teams/TEAM_ID/channels/CHANNEL_ID/chatThreads
{
"RootMessage": {
"body": {
"contentType": 1,
"content": "Hello World!"
}
}
}
Remember that you need to implement the Authentication on behalf of a user.

Resources