Multi-Tenant Bot with Unique Channel for every customer - botframework

We are building a bot which would require each of our customers to have their own SMS channel (unique phone number for them). From everything we can tell with the documentation of the bot framework is there is no way to do that. We want each of our customers to be able to add the bot to their own SMS number through twilio. Is this possible?

From everything we can tell with the documentation of the bot framework is there is no way to do that.
Yes you're right.
We want each of our customers to be able to add the bot to their own SMS number through twilio. Is this possible?
No, actually it's not possible :)
Shortly, BotFramework consist of three parts :
your bot logic which is a Web API service that exposes an endpoint
the channels (Skype, Facebook messenger, SMS etc)
the bot connector, where you create your bot by specifing the endpoint and one or multiple diiferent channels that the bot can use for conversations.
Because each channel can be associate only one time per endpoint hence per bot then you can't do multitenancy through the bot connector.
One solution is to create the multitenancy through the Web API service side by creating an endpoint for each customer. Maintenanbility will be difficult because of multiple endpoints you'll end up with the same number of bots into the bot director to manage. Each bot wil be associate to your customer number.
Updates: (I didn't test it but I'm pretty sure it can work)
Another solution is to use DirectLine channel and its Rest API that it exposes. If you opt for this solution it means that you will need to do a lot of things to make that work correctly after creating Direct Line channel:
you must create a client application to communicate with Direct Line channel through its REST API.
each customer can have their own number that you manage through Twilio
each message that a customer send using their SMS number and received via Twilio should trigger a call to the service of your client application
your client application will start a new conversation with Direct Line channel when a SMS is received.
each conversation started by your client application must take care about the SMS number who started the conversation by saving the state. Bot data per conversation and per user can help a lot.
when you receive a reply from the Direct Line Channel, your client application read the SMS number stored into the bot data and use this number to answer to the associated customer.
Hope it helps.

You can definitely do this.
You implement ICredentialProvider which is responsible for looking up appPassword by AppId and validating that the password is correct. This means you can have a database of bot AppId/Passwords that one endpoint services, and you look up the appid/secret and validate calls.
[ BotAuthentication(CredentialProviderType=typeof(SimpleCredentialProvider))]
Here is a simple sample implementation
https://docs.botframework.com/en-us/csharp/builder/sdkreference/d3/dde/_credential_provider_8cs_source.html

Related

How to find chat conversation with bot

we are working on MS Bot Framework bot. We are integrating with directline and MS teams. In certain cases we need to download conversation history. Within directline we are using standard DL endpoints to retrieve the conversation. However these are not available for teams channel. Therefore we are trying to get chat messages using Graph API by using
/me/chats/{id}/messages
And here's our issue - to get the chat ID we are trying to iterate through chats returned by
/me/chats
And then look up conversation members by
/me/chats/{id}/members
However chat with Bot contains only user and not the bot so it appears it is a single member chat. As workaround we always sort chats by last updated timestamp descending and assuming first single member conversation is the one we are looking for however this is tricky and unreliable and also very slow some times. Is there some better way to get conversation history from MS teams channel?
Using Graph API, you can access information related to channels in Microsoft Teams. You can refer to list channel messages which retrieves the list of messages (without the replies) in a channel of a team. If you want to get the replies for the message, then you need to call list message replies or get message reply API.
GET /teams/{id}/channels/{id}/messages
One more way is to subscribe to the channel using change notifications API which makes you get all the messages of the channel to the notification endpoint.

Sending a message to users as a bot in bot channel of Microsoft Teams using the Graph API

I have created a bot by following the steps mentioned in the doc.I have authenticated user using oauth 2.0 (auth code grant) as mentioned in the doc and in reverse I got a access token. But when I send message to channel in the teams using (/teams/{id}/channels/{id}/messages) API the message was sent on behalf of me. But I want my bot as the sender of message. Here is the image of the message that I have sent using the above API. and is there any way to send direct message to user as a bot?
Instead of using the Graph, there's another approach using the Bot Framework itself, to send a message to a team channel, a group chat, or a 1-1 conversation. The code doesn't even need to live inside the bot itself, it just needs to leverage the bot framework under the covers (for example, I have several Azure Functions that pro-actively message users). This idea is called "Proactive messaging" and you can read more about it in the docs here.
You do need to get certain fields when the user first installs the bot though, or any time the bot receives a message. I've described that more at Programmatically sending a message to a bot in Microsoft Teams. You haven't said what language you're using, but there are examples for a bunch of them - I can send you links if you let me know what you're using.

Is possible to send an activity to a bot from a conversation from an other direcline client?

I have a bot, a client start a conversation with it using directline 3.0.
The bot follow a waterfall flow and at one step start an external process that do something. The process, finished the task use directline to start a new connection. i would like to send a message to the bot using a specific connection as the bot receive the message and can continue the flow. Is it possible?
Yes, this is possible using proactive messages. There is no need to use direct line, specifically, to create a new connection to send an activity. In short, in your bot's you will create a new API that external services can ping. As part of the process, when the API is hit, a conversation reference is created that, in short, allows you to pass any received data as an activity to the bot. When the bot receives the activity, you can setup logic to determine what the bot does next.
There is a SO post here that addresses this issue that you can reference. Additionally, you can refer to the BotBuilder-Samples GitHub sample for additional clarification.
Hope of help!

How to get message events published on a Web API endpoint and feed it to bot framework v4 (C#, .Net Core Bot)?

I am using a third party API to provide Agent Handover (human chat) capabilities to my v4 based bot. The API requires a call back hook/ endpoint where it can send the messages/events back from the agent, and I have to get messages from it and display to users. When ever a new chat session is established a new session id is generated. And thus Session Id is passed back in all messages and events. Essentially they are sending events as Fire&Forget with a retry on failure.
For now I had implemented an eventstore (in Cosmos dB) to store events/messages and then poll Cosmos periodically display message back to user and mark them processed.
Is there any way to make it more real time or pub-sub kind of analogy?
I would like to know if some one have already implemented scenario like this. What should be the way to respond the incoming messages from agent to bot user.
Please suggest.
I would recommend creating a client using the Direct Line API to handle routing messages between the third party agent handover and the bot. Then in the bot you can pair the third party Direct Line conversation references with the user's conversation reference to forward the messages accordingly with proactive messages. For more details take a look at this Stack Overflow question.
Hope this helps!

Can user resume a conversation in a different channel? (Bot Framework)

Let's think of the following example:
1) I have a certain bot deployed on Azure
2) Bot can be talked via Facebook Messenger and via Skype
3) A certain user talks to the bot via Facebook Messenger and then he leaves.
4)A couple of minutes ago the same user resumes the conversation with the bot, but via Skype.
Is this possible? I assume Bot Framework doesn't have anything included for this, hence, that this isn't posible (as conversations are independent and state changes depending on the channel). Is there any way to identify a user (via some authentication method maybe), and then making this logic again?
Do any of you know any workaround for this?
Thanks in advance!
The Bot Framework Connector service is a component which provides a single API for your bot to communicate across multiple client services such as Skype, Email, Slack. Every bot and user has an account within each channel.
The channel account contains an identifier (id) and other informative bot non-structural data, like an optional name.
And there us unique conversation ID created for each conversation of each user for each channel. And you can customize your channel capabilities as described here.
Regards,
Jyo

Resources