Listening to a specific user

A common use case is the automation of a special user or handing over the conversation to another platform.

At OmniChat, you can listen and impersonate an determined user. To do that, registering an API user is needed.

📘

Attention

The API user will be used to do the API call and it will be the impersonated user.

🚧

Ask for Support

The objectId from API user is needed. Our customer support must be contacted in order to get this Id.

Once you have the API user Id, you could start listening message webhooks.

To do so, you should filter webhooks with resource = 'Message'.

app.post('/webhook', async(req, res) => {    
    const data = req.body;
    if (data.resource === 'Message'){
      // Do something special
    }
    return res.status(200).end();
});

Having this in place, we will be listening to every message that will be arriving and leaving Omnichat.

To achieve the goal of our use case, we need to do an additional filter in order to know which chat we can interact with.

CONST API_USER_ID = 'z4IHx1YnH1'

app.post('/webhook', async(req, res) => {    
    const data = req.body;
    if (data.resource === 'Message'){
    	const { payload } = data;
      if (payload.type === 'ROUTING' && payload.routingToUser === 'API_USER_ID'){
        // Do something more special
      }
    }
    return res.status(200).end();
});

The example above filters messages that are of type 'ROUTING' and checks if the routed user is our API user. It means that the current chat was transferred to our user.

With this condition satisfied, we can finally interact with this particular conversation. To do that, we will need to store the objectId from the chat that this message belongs to.

if (payload.type === 'ROUTING' && payload.routingToUser === 'API_USER_ID'){
	const chatObjectId = payload.chat.objectId;
}

Now we can add additional filters to handle messages received from this chat or interact with it by doing some operations that our API offers.


What’s Next

Start doing chat operations and get total control over the conversation