All Projects → takenet → blip-sdk-js

takenet / blip-sdk-js

Licence: MIT License
The Javascript SDK for BLiP

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to blip-sdk-js

CryptoHub Bot
Everything you desire in the revolution of cryptocurrency.
Stars: ✭ 19 (-34.48%)
Mutual labels:  chatbot
chatbot
🤖️ 基于 PyTorch 的任务型聊天机器人(支持私有部署和 docker 部署的 Chatbot)
Stars: ✭ 77 (+165.52%)
Mutual labels:  chatbot
leon
🧠 Leon is your open-source personal assistant.
Stars: ✭ 8,560 (+29417.24%)
Mutual labels:  chatbot
CHIT-CHAT
A Covid-19 Chatbot that aims to serve humans queries and give a feasible answer to their queries.
Stars: ✭ 18 (-37.93%)
Mutual labels:  chatbot
laravel-kakaobot
🎒 Laravel 5 School Chatbot for Kakaotalk (Cafeteria, Schedule, Luck)
Stars: ✭ 18 (-37.93%)
Mutual labels:  chatbot
Chat-Bot
Chatbot – is a computer program that simulates a natural human conversation. Users communicate with a chatbot via the chat interface or by voice, like how they would talk to a real person.
Stars: ✭ 26 (-10.34%)
Mutual labels:  chatbot
facebook-send-api-emulator
Facebook Messenger Emulator & Facebook Send API Emulator functionality allowing you to test web hooks on developer's machine.
Stars: ✭ 24 (-17.24%)
Mutual labels:  chatbot
flask-chatbot
is example chatbot using flask and pyaiml
Stars: ✭ 11 (-62.07%)
Mutual labels:  chatbot
php-wechaty
PHP Wechaty is a Conversational SDK for Chatbot Makers Written in PHP
Stars: ✭ 35 (+20.69%)
Mutual labels:  chatbot
CircBot
Simple YouTube LiveStream Chatbot (not maintained)
Stars: ✭ 14 (-51.72%)
Mutual labels:  chatbot
memorize-bot
Memorize messenger bot using intelligo framework.
Stars: ✭ 19 (-34.48%)
Mutual labels:  chatbot
botyo
Modular chatbot framework designed for group chat rooms on Facebook
Stars: ✭ 17 (-41.38%)
Mutual labels:  chatbot
i-chatbot
Simple and elegant component for building conversational interfaces on React.
Stars: ✭ 52 (+79.31%)
Mutual labels:  chatbot
docker-hubot
Docker container for running hubot in a container.
Stars: ✭ 17 (-41.38%)
Mutual labels:  chatbot
saihubot
💬 client side chatbot that works in the browser and command line
Stars: ✭ 15 (-48.28%)
Mutual labels:  chatbot
lita-hipchat
A HipChat adapter for Lita.
Stars: ✭ 37 (+27.59%)
Mutual labels:  chatbot
InstaResponder
Instagram Auto DM responder with DialogFlow 🔥
Stars: ✭ 42 (+44.83%)
Mutual labels:  chatbot
technopsyna
телеграм бот для техноконфы
Stars: ✭ 16 (-44.83%)
Mutual labels:  chatbot
Firebot
A powerful all-in-one bot for Twitch streamers
Stars: ✭ 162 (+458.62%)
Mutual labels:  chatbot
NewMessengerBot
a new Messenger Bot Application with Hilt + ViewModel + Fragment.
Stars: ✭ 15 (-48.28%)
Mutual labels:  chatbot

blip-sdk-js

Simple BLiP SDK for JavaScript

This is a work in progress

npm version npm downloads Gitter Travis branch Commitizen friendly


Read more about BLiP here

Installing

Node.js

If you are using node.js (or webpack), you should install the blip-sdk package (via npm) to access the BLiP server:

npm install --save blip-sdk lime-transport-websocket

Browser

If you are developing a web application (for browsers) with "pure" JavaScript, it's possible to import the package from node_modules using the <script> tag. In this case, other than the blip-sdk package, it's also necessary to include the dependencies lime-js and lime-transport-websocket:

<script src="./node_modules/lime-js/dist/lime.js" type="text/javascript"></script>
<script src="./node_modules/lime-transport-websocket/dist/WebSocketTransport.js" type="text/javascript"></script>
<script src="./node_modules/blip-sdk/dist/blip-sdk.js" type="text/javascript"></script>

You can also use unpkg to fetch the packages if you are not using npm in development:

<script src="https://unpkg.com/lime-js" type="text/javascript"></script>
<script src="https://unpkg.com/lime-transport-websocket" type="text/javascript"></script>
<script src="https://unpkg.com/blip-sdk" type="text/javascript"></script>

Instantiate the BlipSdk Client

You will need an identifier and an access key to connect a chatbot to BLiP. To get them:

  • Go to Painel BLiP and login;
  • Click Create chatbot;
  • Choose the Create from scratch model option;
  • Go to Settings and click in Connection Information;
  • Get your bot's identifier and access key.

In order to instantiate the client use the ClientBuilder class informing the identifier and access key:

import * as BlipSdk from 'blip-sdk';
import WebSocketTransport from 'lime-transport-websocket'

// Create a client instance passing the identifier and access key of your chatbot
let client = new BlipSdk.ClientBuilder()
    .withIdentifier(IDENTIFIER)
    .withAccessKey(ACCESS_KEY)
    .withTransportFactory(() => new WebSocketTransport())
    .build();

// Connect with the server asynchronously
// Connection will occurr via websocket on the 8081 port
client.connect() // This method returns a 'promise'
    .then(function(session) {
        // Connection success. Now it's possible to send and receive envelopes from the server
        })
    .catch(function(err) { /* Connection failed */ });

Each client instance represents a server connection and can be reused. To close a connection:

client.close()
    .then(function() { /* Disconnection success */ })
    .catch(function(err) { /* Disconnection failed */ });

Receiving

All messages sent to the chatbot are redirected to registered receivers of messages and notifications. You can define filters to specify which envelopes will be handled by each receiver. The following example shows how to add a simple message receiver:

client.addMessageReceiver(true, function(message) {
  // Process received message
});

The next sample shows how to add a notification receiver with a filter for the received event type:

client.addNotificationReceiver("received", function(notification) {
  // Process received notifications
});

It's also possible to use a custom function as a filter:

Example of a message receiver filtering by the originator:

client.addMessageReceiver(message => message.from === "[email protected]", function(message) {
  // Process received message
});

Each registration of a receiver returns a handler that can be used to cancel the registration:

var removeJsonReceiver = client.addMessageReceiver("application/json", handleJson);
// ...
removeJsonReceiver();

Sending

It's possible to send notifications and messages only after the session has been stablished.

The following sample shows how to send a message after the connection has been stablished:

client.connect()
    .then(function(session) {
      // Once connected it's possible to send messages
      var msg = { type: "text/plain", content: "Hello, world", to: "[email protected]" };
      client.sendMessage(msg);
    });

The following sample shows how to send a notification after the connection has been stablished:

client.connect()
    .then(function(session) {
      // Sending a "received" notification
      var notification = { id: "ef16284d-09b2-4d91-8220-74008f3a5788", to: "[email protected]", event: Lime.NotificationEvent.RECEIVED };
      client.sendNotification(notification);
    });

Contributing

For information on how to contribute to this package, please refer to our Contribution guidelines.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].