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?
2 Answers
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