Skip to content

Instantly share code, notes, and snippets.

@johnfischelli
Created February 4, 2020 23:53
Show Gist options
  • Save johnfischelli/0080b64190aeaa7350afe408ca32ee9a to your computer and use it in GitHub Desktop.
Save johnfischelli/0080b64190aeaa7350afe408ca32ee9a to your computer and use it in GitHub Desktop.
A node script to mark a Twilio Flex Chat Channel as INACTIVE
const twilio = require('twilio');
const accountSid = '';
const authToken = '';
const chatService = '';
const channelSid = process.argv[2] || '';
if (channelSid === '') {
console.error('A channelSid must be provided. `node closeChannel.js <channelSid>`');
return process.exit();
}
const client = new twilio(accountSid, authToken);
client.chat.services(chatService).channels(channelSid).fetch().then((channel) => {
let attributes = JSON.parse(channel.attributes);
attributes.status = 'INACTIVE';
client.chat.services(chatService).channels(channelSid).update({attributes: JSON.stringify(attributes)}).then((channel) => {
console.log('updated attributes:', channel.attributes)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment