-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskill.js
63 lines (52 loc) · 1.86 KB
/
skill.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
52
53
54
55
56
57
58
59
60
61
62
63
'use strict'
const alexaSkillKit = require('alexa-skill-kit')
const MessageTemplate = require('alexa-message-builder')
const fetch = global.fetch = require('node-fetch')
const cc = require('cryptocompare')
const tokens = {
bitcoin: 'BTC',
litecoin: 'LTC',
ethereum: 'ETH',
ether: 'ETH',
ripple: 'XRP'
}
function cryptoSkill(event, context, callback) {
console.log(event)
alexaSkillKit(event, context, (message) => {
if (message.intent.name === 'GetPrice') {
const token = message.intent.slots.Coin.value
if (Object.keys(tokens).indexOf(token.toLowerCase()) < 0) {
return 'I can give you the info only for bitcoin, litecoin and ethereum'
}
return cc.price(tokens[token], 'INR')
.then(prices => `Current price of ${token} is ${prices.INR} rupees.`)
}
if (message.intent.name === "AmountInfo") {
const token = message.intent.slots.Coin.value
const amount = Number(message.intent.slots.Amount.value)
if (Object.keys(tokens).indexOf(token.toLowerCase()) < 0) {
return 'I can give you the info only for bitcoin, litecoin and ethereum'
}
return cc.price(tokens[token], 'INR')
.then(prices => `You can get ${amount / prices.INR} ${token}s for ${amount} rupees.`)
}
if (message.type === 'LaunchRequest') {
return new MessageTemplate()
.addText(`Hello from crypto currency bot.
I can give you the info about bitcoin, litecoin and ethereum prices.
How can I help you today?
You can say:
What is the current bitcoin price?
Or How many ethereums can I get for 100 rupees?
`)
.addReprompt(`
You can say:
What is the current bitcoin price?
Or How many ethereums can I get for 100 rupees?
`)
.keepSession()
.get();
}
})
}
exports.handler = cryptoSkill