Created
December 6, 2017 15:35
-
-
Save odirleiborgert/e592af81d413b2d0e1172fb61eecde28 to your computer and use it in GitHub Desktop.
Teste de bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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