-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprovision.js
56 lines (52 loc) · 1.35 KB
/
provision.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
require('dotenv').config();
const Inquirer = require('inquirer');
const fs = require('fs');
Inquirer.prompt([
{
type: 'string',
name: 'twilioAccountSid',
message: 'Twilio Account SID'
},
{
type: 'password',
name: 'twilioAuthToken',
message: 'Twilio Auth Token'
},
{
type: 'string',
name: 'studioFlowSid',
message: 'Studio Flow SID'
},
{
type: 'string',
name: 'flexChatServiceSid',
message: 'Flex Chat Service SID'
}
]).then(answers => {
const client = require('twilio')(
answers.twilioAccountSid,
answers.twilioAuthToken
);
var flowOptions = {
integrationType: 'studio',
channelType: 'custom',
enabled: true,
'integration.flowSid': answers.studioFlowSid,
contactIdentity: 'contact-identity',
friendlyName: 'Flex Custom Channel Flow',
chatServiceSid: answers.flexChatServiceSid
};
client.flexApi.flexFlow
.create(flowOptions)
.then(flexFlow => {
console.log(`Created Flex Flow ${flexFlow.sid}`);
envFileContent = `TWILIO_ACCOUNT_SID=${answers.twilioAccountSid}\n`
+ `TWILIO_AUTH_TOKEN=${answers.twilioAuthToken}\n`
+ `FLEX_FLOW_SID=${flexFlow.sid}\n`
+ `FLEX_CHAT_SERVICE=${answers.flexChatServiceSid}`
fs.writeFileSync('middleware/.env',envFileContent)
})
.catch(error => {
console.log(error);
});
});