-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (50 loc) · 1.32 KB
/
index.js
File metadata and controls
59 lines (50 loc) · 1.32 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
const express = require('express'),
bodyParser = require('body-parser'),
{ Message, Card, Text, Media, Button } = require('flowai-js-templates'),
port = process.env.PORT || 6091
const app = express()
app.use(bodyParser.json())
app.post('/', (req, res) => {
console.info('Received body', req.body)
const {
replyUrl,
verifyToken,
user
} = req.body
// Text bubble
const text = new Text('You know what?')
// Button for the card
const button = new Button({
label: 'Show me cat pics',
value: 'https://www.google.nl/search?q=kittens+are+awesome',
type: 'url'
})
// Card widget
const card = new Card({
title: 'Kittens are awesome!',
subtitle: 'Jumping, dancing',
media: new Media({
url: 'http://static.fjcdn.com/pictures/Kittens_10cff6_2206231.jpg',
type: 'image'
})
})
card.addButton(button)
// Message with fallback message
const message = new Message('You know what? Kittens are awesome!')
message.addResponse(text)
message.addResponse(card)
// Return the verifytoken and
// array of messages
const replyBody = {
verifyToken,
messages: [message]
// events: [{
// name: 'EVENT NAME'
// }]
}
// Direct reply
res.json(replyBody)
})
app.listen(port, () => {
console.info('Webhook listening at %s', port)
})