-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcallflow.js
More file actions
46 lines (40 loc) · 1.84 KB
/
callflow.js
File metadata and controls
46 lines (40 loc) · 1.84 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
/*
このプログラムはsakura.ioとTwilioとのコラボハンズオンにおいて、Twilio Functionsと連携させるためのものです。
こちらで生成されたURLをsakura.ioのOutgoing Webhookで指定することにより、sakura.ioで取得されたセンサデータはJSONデータとして本プログラムで処理されます。
本プログラムの動作に必要なパッケージはありません。
パラメータは以下のように指定します。
PATH : /callflow
ACCESS CONTROL : チェックなし
EVENT : 指定なし
*/
exports.handler = function(context, event, callback) {
// モジュールからのメッセージの場合のみ処理を行う(切断・接続メッセージなどは無視) Determining the message type
const messageType = event.type;
if (messageType !== "channels") {
console.log("messageType is not channels");
callback(null, 'ignored messageType');
}
// JSONデータに含まれるモジュールIDを変数に代入 Substitute the module ID included in the JSON data
const moduleId = event.module || '';
// モジュールIDの照合 Verification of module ID
if (moduleId !== context.MODULE_ID) {
console.log("Module ID unmatch");
callback(null, 'Module id unmatch.');
}
const twilioClient = context.getTwilioClient();
twilioClient.studio.flows('FWから始まるStudioフローのSID').engagements.create({
to: context.TO_NUMBER,
from: context.FROM_NUMBER,
parameters: JSON.stringify({
moduleId: moduleId
})
})
.then(function(engagement) {
console.log(engagement.sid);
callback(null, engagement.sid);
})
.catch(error => {
console.error(`problem with request: ${error.message}`);
callback(error.message);
});
};