Redirect studio flow to Frontline

106 Views Asked by At

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?

1

There are 1 best solutions below

4
On

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,
});