Skip to content

Commit 351cd63

Browse files
author
Igor Khomenko
committed
added chat_bots samples
1 parent a82fdc7 commit 351cd63

File tree

8 files changed

+79
-6
lines changed

8 files changed

+79
-6
lines changed

samples/node_js/universal_rivescript/universal_rivescript.js renamed to samples/chat_bots/rivescript/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
* Before using you need to install universal_rivescript
5-
* by the command `npm i`
5+
* by the command `npm i`
66
*/
77

88
const CONFIG = require('./config').CONFIG;
@@ -36,7 +36,7 @@ QB.init(CONFIG.appId, CONFIG.authKey, CONFIG.authSecret);
3636
var qbListeners = {
3737
onSubscribeListener: function onSubscribeListener(userId) {
3838
console.log(`[QB] onSubscribeListener. Subscribe from ${userId}`);
39-
39+
4040
QB.chat.roster.confirm(userId, function() {
4141
console.log(`[QB] Confirm subscription from user ${userId}`);
4242
});
@@ -119,6 +119,8 @@ QB.createSession({
119119
process.exit(1);
120120
}
121121

122+
console.log('[QB] bot is up and running');
123+
122124
QB.chat.dialog.list({type: 2}, (dialogListError, dialogList) => {
123125
if(dialogListError){
124126
console.log('[QB] dialog.list is failed', JSON.stringify(dialogListError));

samples/node_js/universal_rivescript/package.json renamed to samples/chat_bots/rivescript/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "universal_rivescript",
2+
"name": "rivescript",
33
"version": "0.0.1",
44
"description": "www.rivescript.com enabled chat bot",
5-
"main": "universal_rivescript.js",
5+
"main": "index.js",
66
"author": "QuickBlox team",
77
"license": "BSD-2-Clause",
88
"dependencies": {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
3+
const QB = require('../../../src/qbMain.js');
4+
5+
const CONFIG = {
6+
"appId": "13318",
7+
"authKey": "WzrAY7vrGmbgFfP",
8+
"authSecret": "xS2uerEveGHmEun",
9+
"botUser": {
10+
"id": "2740296",
11+
"password": "mehdoh00",
12+
"fullname": "Your best friend bot"
13+
}
14+
};
15+
16+
// Initialise QuickBlox
17+
QB.init(CONFIG.appId, CONFIG.authKey, CONFIG.authSecret);
18+
19+
// Connect to Real-Time Chat
20+
QB.chat.connect({
21+
userId: CONFIG.botUser.id,
22+
password: CONFIG.botUser.password
23+
}, (chatConnectError) => {
24+
if (chatConnectError) {
25+
console.log('[QB] chat.connect is failed', JSON.stringify(chatConnectError));
26+
process.exit(1);
27+
}
28+
29+
console.log('[QB] Bot is up and running');
30+
31+
// Add chat messages listener
32+
QB.chat.onMessageListener = onMessageListener;
33+
});
34+
35+
function onMessageListener(userId, msg) {
36+
37+
// process 1-1 messages
38+
if (msg.type == 'chat') {
39+
if(msg.body){
40+
let answerMessage = {
41+
type: 'chat',
42+
body: msg.body, // echo back original message
43+
extension: {
44+
save_to_history: 1
45+
}
46+
};
47+
48+
QB.chat.send(userId, answerMessage);
49+
}
50+
}
51+
52+
}
53+
54+
process.on('exit', function () {
55+
console.log('Kill bot');
56+
QB.chat.disconnect();
57+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "my_awesome_bot",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"quickblox": "^2.3.0"
13+
}
14+
}

samples/node_js/createAndUpload.js renamed to samples/node_js/content/createAndUpload.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
* Sample for Node env.
33
* createAndUpload an image
44
*
5-
* Start example
5+
* Start example
66
* by command `node createAndUpload.js`
77
*/
88

99
/**
1010
* Declaring variables
1111
*/
1212
const fs = require('fs');
13-
const QB = require('../../src/qbMain.js');
13+
const QB = require('../../../src/qbMain.js');
1414

1515
/** See http://quickblox.com/developers/Javascript#Configuration */
1616
const CONFIG = {
File renamed without changes.

0 commit comments

Comments
 (0)