1
0
This repository has been archived on 2018-04-23. You can view files and clone it, but cannot push or open issues or pull requests.
Files
vodopija-bot/bot/facebook/conversation.js
2018-04-22 20:57:24 +02:00

54 lines
1.4 KiB
JavaScript

const fbTemplate = require('claudia-bot-builder/lib/facebook/format-message')
const fbReply = require('claudia-bot-builder/lib/facebook/reply')
const normalize = str => str.toLowerCase()
const send = (recipientId, message) =>
fbReply(recipientId, message, process.env.FB_ACCESS_TOKEN)
const intents = {
default: {
keywords: [],
run(msg, recipient) {
const reply = new fbTemplate.Text(
`Sorry, ${
recipient.first_name
}. I am a young Bot and still learning. Type "Start" to show the start over.`
).get()
send(recipient.id, reply)
},
},
start: {
keywords: ['start', 'menu', 'help'],
run(msg, recipient) {
const reply = new fbTemplate.Text(`
This is your menu. You can reach it by writing Menu, or Help, or Start
`).get()
send(recipient.id, reply)
},
},
drink: {
keywords: ['dring', 'water', 'gimmme'],
run(msg, recipient) {
const reply = new fbTemplate.Text(`
So, you'd like to drink?
`).get()
send(recipient.id, reply)
},
},
}
const getIntent = msg =>
Object.keys(intents).find(k => intents[k].keywords.indexOf(msg) !== -1)
module.exports = async (message, recipient) => {
const intent = getIntent(normalize(message.text))
// Fallthrough
if (!intent) {
return intents.default.run(message, recipient)
}
intents[intent].run(message, recipient)
}