forked from cr0111/apiai-skype-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
skypeHelpers.js
78 lines (68 loc) · 3.32 KB
/
skypeHelpers.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var moment = require('moment');
var locale_es = require('./moment-es.js');
moment.locale('es', locale_es);
var responseCards = function responseCards(jsonData) {
if (jsonData !== undefined) {
if (jsonData.items !== undefined) {
var jsonResponse = {};
jsonResponse.type = "message";
jsonResponse.text = "";
jsonResponse.attachmentLayout = "carousel";
jsonResponse.attachments = []
var items = jsonData.items;
var i = 0;
for (i=0;i<items.length;i++) {
//para cada outbound choice armar el par con todos los inboud choices de ese item.
var j = 0;
for(j=0;j<items[i].outbound_choices.length;j++) {
var k = 0;
for(k=0;k<items[i].inbound_choices.length;k++) {
var oc = items[i].outbound_choices[j];
var ic = items[i].inbound_choices[k];
var card = {}
card.contentType = "application/vnd.microsoft.card.hero";
card.content = {}
var p = 0;
card.content.title = "";
card.content.subtitle = "";
for(p=0;p<oc.segments.length;p++) {
if (p == 0) {
card.content.title += oc.segments[p].from + " - " + oc.segments[p].to;
card.content.subtitle += moment(oc.segments[p].departure_datetime).format("DD MMMM YYYY, hh:mm a");
//card.content.subtitle += moment().format("LLLL");
} else {
card.content.title += " - " + oc.segments[p].to;
}
}
card.content.title += " | ";
for(p=0;p<ic.segments.length;p++) {
if (p == 0) {
card.content.title += ic.segments[p].from + " - " + ic.segments[p].to;
} else if (p < ic.segments.length -1) {
card.content.title += " - " + ic.segments[p].to;
} else {
card.content.title += " - " + ic.segments[p].to;
card.content.subtitle += " | " + moment(ic.segments[p].arrival_datetime).format("DD MMMM YYYY, hh:mm a");
}
}
var pd = items[i].price_detail;
card.content.text = pd.currency + "$ " + pd.total
card.content.images=[{url:'http://img1.rnkr-static.com/list_img_v2/15352/115352/C480/boeing-airplanes-and-aircrafts-u1.jpg'}]
card.content.buttons=[]
card.content.tap=null
jsonResponse.attachments.push(card);
}
}
}
return jsonResponse;
} else {
console.log(jsonData);
return "NO TIENE EL ROOT ITEMS";
}
} else {
return "NO ESTA DEFINIDO EL JSON";
}
}
module.exports = {
'responseCards' : responseCards
}