Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
124 lines (103 loc) · 4.62 KB
/
Copy pathapp.js
File metadata and controls
124 lines (103 loc) · 4.62 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Webtask (https://webtask.io/) which on a GET returns a page that lets you use spech
// recognition to fill out a form for creating a new trello card. The form will POST
// to the webtask, which will then send the content to an ifttt Maker Channel.
//
// When deploying the webtask, pass the maker channel key via the --SECRET parameter.
// e.g. wt create app.js --no-parse --no-merge --secret MAKER_KEY="MY_MAKER_KEY"
//
// You can get the key for your maker channel by navigating to: https://ifttt.com/maker
var Express = require('express');
var bodyParser = require('body-parser');
var Webtask = require('webtask-tools');
var request = require('request');
const page = `
<html>
<head>
<!-- SKELETON -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.css">
</head>
<body>
<div class="container">
<h1>Trello Voice</h1>
<p>Use voice to create new trello cards</p>
<form id="form" action="?" method="post">
<div class="row">
<div class="six columns">
<label for="trelloListInput">Speak 'list [listname]'</label>
<input class="u-full-width" type="text" placeholder="trello list name" id="trelloListInput" name="value1">
</div>
<div class="six columns">
<label for="cardTitleInput">Speak 'title [title]'</label>
<input class="u-full-width" type="text" placeholder="trello card title" id="cardTitleInput" name="value2">
</div>
</div>
<label for="descriptionInput">Speak 'description [description]'</label>
<input class="u-full-width" type="text" placeholder="trello card description" id="descriptionInput" name="value3">
<label style="display: inline;">Say </label><input class="button-primary" type="submit" value="Submit">
</form>
<p id="unrecognized"/>
<!-- Voice Recognition for filling form -->
<script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/annyang/2.4.0/annyang.min.js"></script>
<script>
if (annyang) {
var commands = {
'list *listname': function(listname) {
$('#trelloListInput').val(listname);
},
'title *title': function(title) {
$('#cardTitleInput').val(title);
},
'description *description': function(description) {
$('#descriptionInput').val(description);
},
'submit': function() {
console.log("submit");
$('#form').submit()
}
};
// Add our commands to annyang
annyang.addCommands(commands);
annyang.addCallback('resultNoMatch', function(phrases) {
console.log(phrases);
$('#unrecognized').text('Possibly said: ' + JSON.stringify(phrases));
});
annyang.addCallback('error', function() {
$('#unrecognized').text('There was an error!');
});
// Start listening. You can call this here, or attach this call to an event, button, etc.
annyang.start({ autoRestart: true });
}
</script>
</div>
</body>
</html>
`
const MAKER_EVENT="trello_card_created"
var app = Express();
// Parse x-www-form-urlencoded content
app.use(bodyParser.urlencoded({ extended: true }));
// API - POST NEW CARD
app.post('/', function (req, res) {
// The key to the maker channel should be deployed with the
// webtask using the --Secret parameter
var makerKey = req.webtaskContext.data.MAKER_KEY;
var url = `https://maker.ifttt.com/trigger/${MAKER_EVENT}/with/key/${makerKey}`
var options = {
url: url,
method: "POST",
json: req.body
}
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
res.redirect('back');
} else {
res.status(500).send(response.body);
}
});
});
// GET - WEB PAGE
app.get('/', function (req, res) {
res.send(page);
});
module.exports = Webtask.fromExpress(app);