forked from howdyai/botkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle_hangouts_bot.js
More file actions
95 lines (83 loc) · 3.09 KB
/
google_hangouts_bot.js
File metadata and controls
95 lines (83 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var Botkit = require('../lib/Botkit.js');
var controller = Botkit.googlehangoutsbot({
endpoint: 'Axjn86rTGRQwisaYFyT0XZyiOCh7rZUPGx1A',
token: "YOUR_TOKEN",
debug: true,
});
var bot = controller.spawn({});
controller.setupWebserver(3000, function (err, webserver) {
controller.createWebhookEndpoints(webserver, bot, function () {
console.log(`🚀 Congratulation, the web server is online!`);
});
});
controller.on('message_received', function (bot, message) {
bot.reply(message, `You said '${message.text}'`);
});
controller.hears('new thread', 'message_received', function (bot, message) {
bot.replyAsNewThread(message, `Hello ! this is a new thread`);
});
controller.hears('thread key', 'message_received', function (bot, message) {
bot.replyWithThreadKey(message, {
threadKey : "YOUR_THREAD_KEY",
requestBody : {
text : `Hi ! this message inside the same thread`
}
});
});
controller.hears('convo', 'message_received', function (bot, message) {
bot.startConversation(message, function(err, convo) {
convo.ask('You want to know more about Botkit ?', [
{
pattern: bot.utterances.yes,
callback: function(response, convo) {
convo.say('Take a look here https://botkit.ai/docs/');
convo.next();
}
},
{
pattern: bot.utterances.no,
default: true,
callback: function(response, convo) {
convo.say('No problem');
convo.next();
}
}
]);
});
});
controller.hears('cards', 'message_received', function (bot, message) {
bot.reply(message, {
requestBody: {
cards: [
{
"sections": [
{
"widgets": [
{
"image": { "imageUrl": "https://image.slidesharecdn.com/botkitsignal-160526164159/95/build-a-bot-with-botkit-1-638.jpg?cb=1464280993" }
},
{
"buttons": [
{
"textButton": {
"text": "Get Started",
"onClick": {
"openLink": {
"url": "https://botkit.ai/docs/"
}
}
}
}
]
}
]
}
]
}
]
}
});
});
controller.on('card_clicked', function (bot, message) {
bot.reply(message, 'This is a card click');
});