Send/receive message to/from RocketChat user with API

Hi all,

A question from a new RocketChat user: is it possible to chat with a RocketChat authenticated user with API (instead of RocketChat application)?

I want to redirect my customer-service-bot to a human agent who is on RocketChat when a customer requests to talk with a human agent. So I need to link the customer and the human agent on with APIs in the code. Then the two can communicate each other in my bot context.

I am a new user for RocketChat. Maybe it is a stupid question. But I’ve indeed Googled a lot this case, few useful results found.

Any help, I will appreciate!




Thanks for your reply @MJPGPleasant !

But how to receive following messages from the agent? And how to keep a long session connection with a specific agent?

Not sure how you would monitor for new messages, but once they come in you can retrieve them using chat.getMessage. Session information would be done by refreshing the token using the “resume” option of the login API.

All the APIs are available at REST API - Rocket.Chat Docs

1 Like

Do you mean this api regarding getMessage?
But how could I know msgId of the message which to be retrieved? From the customer side, he only waits for the reply from the human agent.

You can do that with im.history - For the rest of the implementation I will leave that as an exercise for you. :slight_smile:

Thanks @MJPGPleasant

I think it is possible to retrieve latest message by the interface im.history with the parameter offset=0. But my concern is still that all these operations postMessage, getMessage, im.history are always triggered by the customer side. Then it is not easy to make sure a real time interaction.

How to receive those messages from the agent?