-1

I have a Studio Flow that is sending and receiving messages from whatsapp users in order to offer some kind of support center.

enter image description here

What I need now is to, in case users reply with a "Connect to an agent" option on the whatsapp message the flow redirect the conversation to Twilio Frontline.

I used a Twiml response to redirect:

<Response>
    <Connect>
        <Conversation serviceInstanceSid="ISdb207483328841f7a849739ded09bdea" />
      </Connect>
</Response>

but its not working and Frontline is not creating the conversation

Has anyone managed to do this?

Jean Paul Rumeau
  • 343
  • 4
  • 16

1 Answers1

1

I believe that you'll need to create a function to send this conversation to a specific Frontline's agent, follow an example of code that you can use to add a random agent to a conversation using Twilio Function

const users = await twilioClient.conversations.users.list();

const randomWorkerIndex = Math.floor(Math.random() * users.length);

//adding the agent to conversation
const agent = await conversation.participants().create({
  identity: users[randomWorkerIndex].identity,
});
csevero
  • 361
  • 1
  • 8
  • My problem Is that I cant get the conversation id on the function as frontline autocreates it bu it doesn't get to the studio flow on incomingMessage. – Jean Paul Rumeau Dec 23 '22 at 13:14
  • Got it Jean, you can use the Conversations Webhook to listener when a new conversation is added, with it you can get the Conversation SID, and you can add a Webhook Scooped to this conversation to execute a Studio Flow, with that you'll have all information that you need. Follow the documentations: Conversation Scooped Webhook - https://www.twilio.com/docs/conversations/api/conversation-scoped-webhook-resource Conversation Webhook - https://www.twilio.com/docs/conversations/conversations-webhooks – csevero Dec 23 '22 at 13:18
  • So if im getting it right I should have one flow for the conversation interaction and another flow to add the interaction flow as a scoped webhook to the conversation? – Jean Paul Rumeau Dec 23 '22 at 13:52
  • Not necessary, you can have just one Flow to handle with incoming conversations, and with this flow you can use on the scoped webhook conversation. – csevero Dec 23 '22 at 20:57