Articles on: OneHash Chat | API Channel

Create Interfaces using client APIs in OneHash Chat

Client APIs



Note: These APIs are still in alpha, and there might be changes in the implementation in future.

Client APIs available for the API channel will help you build customer-facing interfaces for OneHash Chat.

These APIs are useful for cases similar to the ones described below.

Use a custom chat interface instead of the OneHash Chat chat widget
Build conversational interfaces into your mobile apps
Add OneHash Chat to other platforms for which OneHash Chat doesn't have an official SDK

Creating customer objects



You can create and retrieve customer data objects using the inbox_identifier and customer_identifier.

Inbox Identifier


You can obtain the inbox_identifier from your API channel -> Settings -> Configuration


Customer Identifier


The customer_identifier or the source_id can be obtained when creating the customer using the create API.
You will need to store this identifier on your client-side to make further requests on behalf of the customer.
This can be done in cookies, local storage etc.

Available APIs


Some of the things you can do via the APIs are

- Create, View and Update Contact
- Create and List Conversations
- Create, List and Update Messages

HMAC Authentication


The Client APIs also support HMAC Authentication.
The HMAC token for the Channel can be obtained via running the following on your rails console.

# replace api_inbox_id with your inbox id
Inbox.find(api_inbox_id).channel.hmac_token


Connecting to the OneHash Chat WebSockets



To receive the real-time updates from the agent dashboard, You can connect to the OneHash Chat WebSockets.
OneHash Chat WebSockets connecting can be made at the following URL
<your installation url>/cable


Authenticating your WebSocket connection


You will start receiving the events directed towards your customer object after subscribing using the customer pubsub_token.
pubsub_token is provided during the customer create API call.



Example


const connection = new WebSocket('ws://localhost:3000/cable');
connection.send(JSON.stringify({ command:"subscribe", identifier: "{\"channel\":\"RoomChannel\",\"pubsub_token\":\""+ customer_pubsub_token+"\"}" }));

Find the full list of events supported by the websockets here.

Updated on: 27/09/2023

Was this article helpful?

Share your feedback

Cancel

Thank you!