Skip to content

Instantly share code, notes, and snippets.

@odirleiborgert
Created December 6, 2017 15:35
Show Gist options
  • Save odirleiborgert/e592af81d413b2d0e1172fb61eecde28 to your computer and use it in GitHub Desktop.
Save odirleiborgert/e592af81d413b2d0e1172fb61eecde28 to your computer and use it in GitHub Desktop.
Teste de bot
'use strict';
// Configs and Helpers
const config = require('./config');
// Modules import
let BlipSdk = require('blip-sdk');
let WebSocketTransport = require('lime-transport-websocket');
let Lime = require('lime-js');
// ---------------------------------------------------------------------------------------------------
let client = new BlipSdk.ClientBuilder()
.withIdentifier(config.IDENTIFIER)
.withAccessKey(config.ACCESS_KEY)
.withTransportFactory(() => new WebSocketTransport())
.build();
// ---------------------------------------------------------------------------------------------------
// Text-plain
client.addMessageReceiver((message) => message.type === 'text/plain', async (message) => {
await setTimeout(async () => {
await client.sendMessage({
id: Lime.Guid(),
to: message.from,
type: "text/plain",
content: "frase 1"
});
}, 2000);
await setTimeout(async () => {
await client.sendMessage({
id: Lime.Guid(),
to: message.from,
type: "text/plain",
content: "frase 2"
});
}, 3000);
});
// ---------------------------------------------------------------------------------------------------
// Connect platform Blip
client.connect()
.then((session) => {
console.log('ChatBot Iniciado...');
})
.catch((err) => {
console.log(err);
});
// ---------------------------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment