Skip to content

Commit

Permalink
Remove manual conversation close call
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhand committed Jun 6, 2024
1 parent 04be6f8 commit f0751a2
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions functions/helpers/chatChannelJanitor.private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,32 +124,18 @@ const deactivateConversation = async (
conversationSid: ConversationSid,
) => {
const client = context.getTwilioClient();
const conversationContext = client.conversations.conversations(conversationSid);
const webhooks = await conversationContext.webhooks.list();
console.log('webhooks');
webhooks.forEach((wh) => {
console.log(wh.sid, wh.configuration.method, wh.configuration.url, wh.configuration.filters);
});
const conversation = await client.conversations.conversations(conversationSid).fetch();
const attributes = JSON.parse(conversation.attributes);

console.log('conversation properties', ...Object.entries(conversation));
console.log('conversation attributes', ...Object.entries(attributes));

if (conversation.state !== 'closed') {
if (attributes.proxySession) {
await deleteProxySession(context, attributes.proxySession);
}
console.log('Attempting to deactivate active conversation', conversationSid);
const updated = await conversation.update({
state: 'closed',
xTwilioWebhookEnabled: 'true',
});

return { message: 'Conversation deactivated', updated };
return { message: 'Conversation deactivated', conversation };
}

return { message: 'Conversation already INACTIVE, event ignored' };
return { message: 'Conversation already closed, event ignored' };
};

export const chatChannelJanitor = async (
Expand Down

0 comments on commit f0751a2

Please sign in to comment.