-
Notifications
You must be signed in to change notification settings - Fork 0
/
weathers.js
47 lines (40 loc) · 1.41 KB
/
weathers.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
var builder = require('botbuilder');
var Store = require('./store');
module.exports = [
// Destination
function (session) {
session.send('歡迎來到天氣功能');
builder.Prompts.text(session, '請輸入你的地理位置');
},
// Search...
function (session, results) {
session.dialogData.destination = results.response;
var destination = session.dialogData.destination;
session.send('尋找關於 %s 天氣', destination);
// Async search
Store
.searchWeathers(destination)
.then(function (weathers) {
// Results
var message = new builder.Message()
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments(weathers.map(weatherAsAttachment));
session.send(message);
// End
session.endDialog();
});
}
];
// Helpers
function weatherAsAttachment(weather) {
return new builder.HeroCard()
.title(weather.name)
.subtitle('查詢結果:' + weather.name)
.images([new builder.CardImage().url(weather.image)])
.buttons([
new builder.CardAction()
.title('More details')
.type('openUrl')
.value('https://www.google.com.tw/search?source=hp&q=weather' + encodeURIComponent(weather.location))
]);
}