Freshchat has native integrations with WhatsApp, Line, ABC, GBM, and FB Messenger to serve your customers easily, wherever they are. We have now come up with a framework to help you choose your own channel and integrate it with Freshchat. You can achieve this with the help of marketplace serverless components, product events, and APIs. We have used this framework for two integrations through the marketplace - Viber and Kakaotalk.
The serverless component of Freshworks apps allows you to bring your own channel (BYOC) to Freshchat. What you essentially require is two-way communication between Freshchat and the channel you wish to integrate. This can be achieved with the help of APIs and webhooks exposed by both, Freshchat and the channel you wish to integrate.
Let’s assume that the channel you wish to integrate is Viber.
User: The end-user who initiates a conversation with the business using the Viber app.
Agent: The representative of the business who responds to messages from the User.
In order to establish a 2-way communication, ensure that messages from Viber are delivered to Freshchat and vice-versa.
But, they cannot talk to each other directly. They require a layer that can translate messages to a format that the recipients can understand.
The Marketplace serverless component is that layer that receives events from both Viber (via Viber webhook) and Freshchat (via Product Events) and dispatches messages to the recipients via APIs.
The Marketplace app is involved in 4 distinct interactions as shown below:
1. Viber Webhook
- When the Marketplace app is installed, in the onAppInstall event 6, it can generate a target URL 3 that can be registered as a webhook in Viber using the Setting a webhook API 5.
- After the webhook is registered, when a Viber user sends a message to the target business, Viber will call the serverless app’s externalEventUrl with the payload containing the message and the user’s attributes.
- This payload will contain a unique identifier of the user (Viber user id).
2. Freshchat API
- Once the serverless app has received the message, it needs to look up that user (using Viber user-id) in Freshchat.
- This can be done via the GET /users.
- If no user exists, then create a new user using POST /users 2.
- If a user exists for the given identifier, fetch existing conversations using the GET /users/{user_id}/conversations.
- Now send a message on a conversation belonging to the user.
- Depending on whether a conversation already exists or not, call one of the two conversation APIs.
- If no conversation exists, call the POST /conversations to create a new one and send a message on it.
- If there already exists a conversation, just send a message on that conversation using POST /conversations/{conversation_id}/messages.
3. Product Events
- When an agent responds to a conversation, it is received by the serverless app via Product Events 1.
- The onMessageCreate event will receive the payload that will contain the message that was sent and the associated user and agent, models.
- The user model would contain the identifier (Viber user-id) that can be used to uniquely identify the user in Viber.
4. Viber API
With the help of the user identifier from the Product Events, you can now relay the message to the user via Viber’s Send Message API. Viber will then deliver the message to the user.
You can use the above steps with any other messaging channel, provided it exposes webhooks and APIs.
In some cases, the webhook registration might be a manual activity. If so, the onAppInstall event can store the generated URL in the Data Store provided by Marketplace. It can be fetched back in the app’s custom settings page and displayed to the Admin, who can then manually copy and paste it into the target channel’s webhook configuration.
Note: Not all messaging channels allow direct usage of their APIs. You have to work with a partner to gain access to their APIs like the Viber Messaging Partners