An easy-to-use CSML API Client for Android.

Related tags

App csml-android
Overview

csml-android

CSML Android SDK

API

An easy-to-use CSML API Client for Android.

Overview

CSML (Conversational Standard Meta Language) is an Open-Source, Domain-Specific Language designed for developing rich conversational experiences easily. It makes creating powerful chatbot's extremely easy. (To learn more about CSML, visit here)

The android library provided in this project is implemented using Retrofit HTTP client to communicate with CSML Studio API Channel, and for CSML Self-Hosted (Support coming in future releases).

Features

  • Supports following sender Message Components:
  • Supports following receiving Message Components:
    • Text - Refer
    • Image - Refer
    • Audio - Refer
    • Video - Refer
    • File - Refer
    • URL - Refer
    • Button - Refer
    • Question - Refer
    • Typing - Refer
    • Wait - Refer
    • Debug - Returns an array of strings when used debug in CSML
    • Error - Returns a message string whenever an exception is thrown in the CSML flow.
  • Supports Custom Meta Data - Refer
  • Detect Unidentifiable/Custom Incoming Messages
  • Smooth encapsulated exception handling
  • End-end CSML Studio Bot API support
  • Extensively documented Javadoc 🙌 🤓

Demo

To have a check on the library, download the demo APK.

demo

This CSML Flow used for the demo.

🔧 Installation

To add CSML Android support in your app, Add the library in your Project build.gradle :

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Add the dependency in the build.gradle (Module: app) :

dependencies {
    compile 'com.github.alshell7:csml-android:1.0.0-rc'
}

Please check the latest release from the Jitpack badge above for the version number.

💡 Usage

Permissions

  • To be able to send messages to the bot and receive the response using this SDK, you must include the internet permission tags in the app's manifest file :
<uses-permission android:name="android.permission.INTERNET" />

Java

  • To instantiate the library and get access to its functions, you need to use the CSMLEngine class :
CSMLEngine csmlEngine = new CSMLEngine(String botPublicApiKey, String userId, BotResponseListener defaultBotResponseListener);

Where:

  • botPublicApiKey - A public API Key for your API bot. - Refer
  • userId - A client-issued string for tracing requests. If none is provided, will be automatically generated.
  • defaultBotResponseListener - Event trigger received on processing the CSML request.

Send Messages to the bot :

csmlEngine.sendText("Hi there!");

csmlEngine.sendImage("https://IMAGE_URL");

csmlEngine.sendAudio("https://AUDIO_URL");

csmlEngine.sendVideo("https://VIDEO_URL");

csmlEngine.sendFile("https://FILE_URL");

csmlEngine.sendURL("https://SOME_URL", "title", "text");

csmlEngine.sendFlowTrigger("flowID", closeFlows /*true or false*/);

Receive Messages from the bot :

The event listener that is used by the CSMLEngine :

public interface BotResponseListener {
    /**
     * Triggers when sending the message failed.
     * @param reason A throwable on any exception happened while communicating with CSML Studio/Open-Source
     */
    public void onMessageSendFailed(Throwable reason);

    /**
     * Gets triggered when the bot responds a text message.
     * @param text A Text Message
     */
    public void onTextReceived(Text text);

    /**
     * Gets triggered when the bot responds an Image message.
     * @param image Am Image Message
     */
    public void onImageReceived(Image image);

    /**
     * Gets triggered when the bot responds an Audio message.
     * @param audio Am Audio Message
     */
    public void onAudioReceived(Audio audio);

    /**
     * Gets triggered when the bot responds a Video message.
     * @param video A Video Message
     */
    public void onVideoReceived(Video video);

    /**
     * Gets triggered when the bot responds an URL message.
     * @param url A URL Message
     */
    public void onUrlReceived(URL url);

    /**
     * Gets triggered when the bot responds a File message.
     * @param file A File Message
     */
    public void onFileReceived(File file);

    /**
     * Gets triggered when the bot responds a Button message.
     * @param button A Button Message
     */
    public void onButtonReceived(Button button);

    /**
     * Gets triggered when the bot responds a Question message.
     * @param question A Question Message
     */
    public void onQuestionReceived(Question question);

    /**
     * Gets triggered when the bot responds a Typing simulation message.
     * @param typing A Typing Message
     */
    public void onTypingReceived(Typing typing);

    /**
     * Gets triggered when the bot responds a Wait simulation message.
     * @param wait A Wait Message
     */
    public void onWaitReceived(Wait wait);

    /**
     * Gets triggered when the CSML bot flow prints a debugging message.
     * @param debug A Debug Message
     */
    public void onDebugReceived(Debug debug);

    /**
     * Gets triggered when the CSML bot flow encounters.
     * @param error An Error Message
     */
    public void onErrorReceived(Error error);

    /**
     * Gets triggered when an unidentifiable/custom payload message is received from the CSML flow.
     * @param message An Abstract CSML-Android Message
     */
    public void onUnIdentifiableReceived(Message message);
}

You can add multiple event listeners to your CSMLEngine :

csmlEngine.addChatResponseListener(BotResponseListener botResponseListener)

💤 Few Tips

  • The CSMLEngine's API request to CSML Studio are run on the background thread, make sure to render the responses on the UI thread appropriately. Example, to use: runOnUiThread(() -> { /*Your code here..*/ });

  • It's good to capture onDebugReceived(Debug debug) and onErrorReceived(Error error). Can help to identify the issues.

  • Found some problems in the library?, feel easy to report it in the issues.

How to Contribute?

  1. Fork it :trollface:
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request 🙉

Licenses

MIT License

Copyright (c) 2022 alshell7

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You might also like...
A general purpose kotlin library that use kotlin coroutines, flows and channels to provide timer features with the most easy and efficient way

Timer Timer is a general purpose kotlin library that use kotlin coroutines, flows and channels to provide timer features with the most easy and effici

Money Manager Ex is a free, open-source, cross-platform, easy-to-use personal finance software
Money Manager Ex is a free, open-source, cross-platform, easy-to-use personal finance software

Money Manager Ex is a free, open-source, cross-platform, easy-to-use personal finance software. It primarily helps organize one's finances and keeps track of where, when and how the money goes.

Abysl Asset Manager is an easy to use library management tool to index and search game assets
Abysl Asset Manager is an easy to use library management tool to index and search game assets

Abysl Asset Manager is an easy to use library management tool to index and search game assets. Features Itch.IO Library Import Hum

TODO API Client Kata for Kotlin Developers. The main goal is to practice integration testing using MockWebServer
TODO API Client Kata for Kotlin Developers. The main goal is to practice integration testing using MockWebServer

KataTODOApiClient for Kotlin We are here to practice integration testsing using HTTP stubbing. We are going to use MockWebServer to simulate a HTTP se

Quiz-Application - A quiz application which uses opentdb api to get quiz of different levels like Easy Hard and Medium
Quiz-Application - A quiz application which uses opentdb api to get quiz of different levels like Easy Hard and Medium

Quiz-Application A quiz application which uses opentdb api to get quiz of differ

This project is focused on the sample using the API's new preview version of Android-L, use of transitions, shadows etc...

Android L preview example Description This project is focused on the sample using the API's new preview version of Android-L, use of transitions, shad

An android app that use food API to display different categories of food
An android app that use food API to display different categories of food

TheMealApp An android app that use food API to display different categories of food The food api is https://www.themealdb.com/api.php. What I used in

when you use restful api and network get disconnect you have to store your data local for make your app faster and work on ofline mode

AppArchitectureOflineMode when you use restful api and network get disconnect you have to store your data local for make your app faster and work on o

This project demonstrate the use of CameraX API for in-app face time.
This project demonstrate the use of CameraX API for in-app face time.

CameraApp This project demonstrate the use of CameraX API for in-app face time. You can click picture using main or front. I have also used yalantis.u

Releases(1.0.0-rc)
Owner
Owais
Love coding for fun
Owais
Calculator provides an easy to use API to evaluate mathematical expressions

Calculator Calculator provides an easy to use API to evaluate mathematical expressions created with following operators: + - * / ( ) For example: This

null 1 Nov 27, 2021
An unofficial Zerotier Android client patched from official client

An unofficial Zerotier Android client patched from official client

KAAAsS 819 Dec 29, 2022
MEGA Android Client - A fully-featured client to access your Cloud Storage provided by MEGA

A fully-featured client to access your Cloud Storage provided by MEGA. This document will guide you to build the application on a Linux machine with Android Studio.

Mega Limited 1.1k Jan 3, 2023
Easy-Note - Easy Note Application will help user to add and update their important notes

Easy-Note ??️ Easy Note App helps you to create your notes. You can ?? edit and

Ade Amit 0 Jan 30, 2022
📱 Android Library to implement Rich, Beautiful, Stylish 😍 Material Navigation View for your project with Material Design Guidelines. Easy to use.

Material NavigationView for Android ?? ?? Android Library to implement Rich, Beautiful Material Navigation View for your project with Material Design

Shreyas Patil 198 Dec 17, 2022
Pomodroid is a flexible and easy to use Android Pomodoro Technique Timer.

Pomodroid - Android App Pomodroid is a flexible and easy to use Android Pomodoro Technique Timer. Unlike other services, pomodroid is free and open so

Klejvi Kapaj 8 Oct 15, 2022
An easy to use android library to let devs know how much internet-data their app is consuming

EasyAnalytics! an easy to use android library to let developers know how much internet-data their app is consuming. We can identify this as we want ba

Sachin Rajput 13 Feb 21, 2022
A simple and easy to use stopwatch and timer library for android

TimeIt Now with Timer support! A simple and easy to use stopwatch and timer library for android Introduction A stopwatch can be a very important widge

Yashovardhan Dhanania 35 Dec 10, 2022
The easy way to use biometric authentication in your Flutter app. Supports Fingerprint, FaceID and Iris.

BiometricX The easy way to use biometric authentication in your Flutter app. Supports Fingerprint, FaceID and Iris. Demo APK. Starting $ flutter pub a

Salman S 13 Dec 15, 2022
Easy to use Overflow Menu for Jetpack Compose

Overflow Menu Android library for Jetpack Compose providing an Overflow Menu via fast and easy to use DSL. How to add to project Step 1. Add the JitPa

Ceribe 2 Dec 17, 2021