-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalexa.js
51 lines (46 loc) · 1.45 KB
/
alexa.js
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
var GoodWordBot = require('node-telegram-bot-api');
var token = '227904406:AAGEAoSgEBeZ_SFnbd0mwYxvbZ_Fq8Vxigo';
var Q = require('Q');
var request = Q.denodeify(require("request"));
var bot = new GoodWordBot(token, {polling: true});
bot.getMe().then(function (me) {
console.log('Hi my name is Lexi!', me.username);
});
// command to start
bot.onText(/\/start/, function (msg, match) {
var fromId = msg.from.id; // get the id of who is sending the message
var message = "Would you like a good word?\n"
message += "Let me know by sending a /yes command."
bot.sendMessage(fromId, message);
});
//yes command action
bot.onText(/\/yes (.+)/, function (msg, match) {
var fromId = msg.from.id;
var goodword = match[1];
var message = "I will find you a good word "+goodword;
bot.sendMessage(fromId, message);
});
// match /weather [whatever]
bot.onText(/\/yes (.+)/, function (msg, match) {
var fromId = msg.from.id; // get the id, of who is sending the message
var goodword = match[1];
QuoteDataHelper(quote)
.then(function(response){
var message = '```"' + response.body.quoteText + '" - ' + response.body.quoteAuthor + '```';
bot.sendMessage(fromId, message);
});
return response.body;
});
function QuoteDataHelper(quote){
var options = {
method: 'GET',
url: "http://api.forismatic.com/api/1.0/",
json: true,
resolveWithFullResponse: true,
qs: {
method: 'getQuote',
lang: 'en',
format: 'json'
}
};
}