-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlers.js
77 lines (63 loc) · 2.45 KB
/
handlers.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
"use strict";
//let salesforce = require("./salesforce");
let accountSid = process.env.ACCOUNT_SID; // Your Account SID from www.twilio.com/console
let authToken = process.env.AUTH_TOKEN; // Your Auth Token from www.twilio.com/console
let fromNumber = process.env.FROM_NUMBER;
let twilio = require('twilio');
let client = new twilio.RestClient(accountSid, authToken);
exports.SearchHouses = (slots, session, response) => {
if (slots.City.value) {
session.attributes.city = slots.City.value;
if (slots.Bedrooms.value) {
session.attributes.bedrooms = slots.Bedrooms.value;
if (slots.Price.value) {
session.attributes.price = slots.Price.value;
doSearch(slots, session, response);
} else {
session.attributes.stage = "ask_price";
response.ask("Ok, around what price?");
}
} else {
session.attributes.stage = "ask_bedrooms";
response.ask("Ok, how many bedrooms?");
}
} else {
session.attributes.stage = "ask_city";
response.ask("OK, in what city?");
}
};
let contacts = JSON.parse(process.env.CONTACTS);
exports.Call = (slots, session, response) => {
this.Ring(slots, session, response);
};
exports.Ring = (slots, session, response) => {
if (slots.Phone.value) {
response.say("Ok, calling requested number.");
doCallPhone(slots.Phone.value);
} if (slots.Who.value) {
console.log("WHO: " + slots.Who.value);
if (contacts[slots.Who.value]) {
response.say("Ok, calling " + slots.Who.value + ' phone.');
doCallPhone(contacts[slots.Who.value]);
} else {
response.say("Golly, don't have " + slots.Who.value + " in your list of contacts.");
}
} else {
response.say("Gee whiz, I didn't really understand that, try find 6507430794.");
}
};
let doCallPhone = (toNumber) => {
client.makeCall({
to:"+1" + toNumber, // Any number Twilio can call
from: fromNumber, // A number you bought from Twilio and can use for outbound communication
url: process.env.TWIML_URL // A URL that produces an XML document (TwiML) which contains instructions for the call
}, function(err, responseData) {
//executed when the call has been initiated.
if (err) {
console.log(err);
}
if (responseData) {
console.log(responseData.from); // outputs "+14506667788"
}
});
}