A first attempt to create a simple SDK to connect directly a Microsoft Azure Web App Bot into an Android App. This SDK does not give any UI or chatbot interface. The SDK connects to the Web App Bot and handles message reception and sending.
You must create a Web App Bot using the Microsoft Azure services.
https://docs.microsoft.com/en-us/bot-framework/bot-service-quickstart
Then you need to open the Direct Line channel API and get the associated secret
https://docs.microsoft.com/en-us/bot-framework/bot-service-channel-connect-directline
Direct Line is the REST API given by Microsoft to communicate via HTTPS to a Web App Bot server.
The SDK gets a URL to connect via WebSocket
with your Web App Bot. It then opens this WebSocket
and lets you receive and send text messages from your Web App Bot.
Instantiate a new DirectLineChatbot
using your Direct Line API secret
final DirectLineChatbot chatbot = new DirectLineChatbot("YOUR_DIRECTLINE_SECRET");
You can then start your chatbot by implementing the DirectLineChatbot.Callback
. Once the Web Socket is opened, the onStarted()
method gets called. Everytime you receive a text message from your Web App Bot, the onMessageReceived(String)
method gets called. Feel free to add this message into your UI.
chatbot.start(new DirectLineChatbot.Callback()
{
@Override
public void onStarted()
{
Log.d("CHATBOT", "Started");
}
@Override
public void onMessageReceived(@NotNull String message)
{
Log.d("CHATBOT", message);
}
});
Once the onStarted()
method has been called, you can send messages to your Web App Bot.
chatbot.send("Hello, Bot!");
Your Web App Bot answers will be sent back to your onMessageReceived(String)
implementation.
To change the name of yourself (default is Me
), use the setUser(String)
method
chatbot.setUser("John Doe");
If you want debug logs, use the setDebug(boolean) method
chatbot.setDebug(true);
implementation("com.smartnsoft:directlinechatbot:${latest.version}")
For now, the SDK only handles text messages. Further improvements will include other types of messages to communicate with the Web App Bot.
The SDK uses Retrofit to call the REST API and Java-WebSocket to manage the WebSocket.
This SDK is under the MIT license.
This SDK was proudly made by Smart&Soft, Paris FRANCE