Git Product home page Git Product logo

directline-chatbot-android-sdk's Introduction

Download License: MIT TeamCity status

directline-chatbot-sdk

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.

Prerequisites

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.

How it works

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.

Initialization

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);
  }
});

Talk with the Web App Bot

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.

Parameters

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);

Download

Gradle

implementation("com.smartnsoft:directlinechatbot:${latest.version}")

Further improvements

For now, the SDK only handles text messages. Further improvements will include other types of messages to communicate with the Web App Bot.

Third party libraries

The SDK uses Retrofit to call the REST API and Java-WebSocket to manage the WebSocket.

License

This SDK is under the MIT license.

Author

This SDK was proudly made by Smart&Soft, Paris FRANCE

directline-chatbot-android-sdk's People

Contributors

david-fournier-smartnsoft avatar ludovicroland avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.