API Channel

API Channel

Create Channel

Effortlessly set up an API channel inbox in Bevatel, allowing you to send and receive messages using Bevatel APIs with simple configuration steps.

How to create an API channel inbox?


Setting up an API channel consists of the following steps.

  1. Create API Channel inbox
  2. Send messages using Bevatel APIs
  3. Receive webhooks on new messages from Bevatel

This document allows you to create and configure an API channel inbox in Bevatel installations.

Step 1: Go to Settings > Channels and click on "Add Channel".

Step 2: Select API from the list of channels.



Step 3: Provide a name for the channel and a callback URL (the events and corresponding payload are defined in 
the subsequent articles)


Step 4: Add agents to the channel



Step 5: Hooray!! The inbox setup is complete.





Now the channel setup is complete, let us try to send a message using Bevatel APIs.


When the user tries to edit the inbox configuration

In the inbox configuration's collaborators section:

  • When you add an agent in the Agent field, any user designated as an agent can see and access this inbox from the Conversation module. They can manage conversations in this inbox.
  • However, when you add a team in the Team field, users attempting to assign conversations to a specific team from the Conversation module will only see the teams that have been added to the related inbox. This restricts conversation assignment options to the teams associated with the particular inbox, ensuring that conversations are appropriately distributed among the specified teams.




Send messages

Learn how to send messages in an API channel within Bevatel by creating contacts, conversations, and messages with the help of API access tokens and structured payloads for efficient communication.

Send messages to the API channel


To send messages to the API channel, you need to have a basic understanding of the models and nomenclature used in Bevatel. Let us try to understand these first.

  1. Channel: You can create multiple sources of conversations that are of the same channel type. For eg: You can have more than one Facebook page connected to Bevatel account. Each page is called as the channel in Bevatel.
  2. Conversation: A Conversation is a collection of messages.
  3. Contact: Each conversation has a real-life person associated with it, this person is called a contact.
  4. Contact Inboxes: This is the session for each contact on an inbox. A contact can have multiple sessions and multiple conversations in the same inbox.

How to send a message in an API Channel?

To send a message in an API channel, you have to create a contact, then create a conversation, and then send a message.

APIs require api_access_token in the request header. You can get this token by visiting your Profile settings > Access Token

1. Create a contact

Pass the inbox ID of the API channel along with other parameters specified. This would create a session for you automatically. A sample response would look like the one below.

  1. {
  2.   "email": "string",
  3.   "name": "string",
  4.   "phone_number": "string",
  5.   "thumbnail": "string",
  6.   "additional_attributes": {},
  7.   "contact_inboxes": [
  8.     {
  9.       "source_id": "string",
  10.       "inbox": {
  11.         "id": 0,
  12.         "name": "string",
  13.         "website_url": "string",
  14.         "channel_type": "string",
  15.         "avatar_url": "string",
  16.         "widget_color": "string",
  17.         "website_token": "string",
  18.         "enable_auto_assignment": true,
  19.         "web_widget_script": "string",
  20.         "welcome_title": "string",
  21.         "welcome_tagline": "string",
  22.         "greeting_enabled": true,
  23.         "greeting_message": "string"
  24.       }
  25.     }
  26.   ],
  27.   "id": 0,
  28.   "availability_status": "string"
     }



As you can see in the payload, you will be able to see the contact_inboxes aneach contact_inbox will have a source_idSource ID can be seen as the session identifier. You will use this source_id to create a new conversation as defined below.


2. Create a conversation

Use the source_id received in the previous API call.

You will receive a conversation ID, which can be used to create a message.

  1. {
  2.   "id": 0
  3. }


3. Create a new message
There are 2 types of messages.

  1. Incoming: Messages sent by the end user is classified as an incoming message.
  2. Outgoing: Messages sent by the agent is classified as an outgoing message.

If you call the API with the correct content, you will receive a payload similar to the one below


  1. {
  2.     "id": 0,
  3.     "content": "This is a incoming message from API Channel",
  4.     "inbox_id": 0,
  5.     "conversation_id": 0,
  6.     "message_type": 0,
  7.     "content_type": null,
  8.     "content_attributes": {},
  9.     "created_at": 0,
  10.     "private": false,
  11.     "sender": {
  12.         "id": 0,
  13.         "name": "Pranav",
  14.         "type": "contact"
  15.     }
  16. }.


If everything is successful, you will see the conversation on the dashboard as follows.





You will be notified when a new message is created on the URL specified while creating the API channel.


 


Receive messages

Effortlessly receive new messages in your API channel through a POST request to the specified Callback URL, providing detailed payload information for effective message handling.

Receive messages using callback URL


When a new message is created in the API channel, you will get a POST request to the Callback URL specified while creating the API channel. The payload would look like this. 

Event type: message_created


  1. {
  2.   "id": 0,
  3.   "content": "This is a incoming message from API Channel",
  4.   "created_at": "2020-08-30T15:43:04.000Z",
  5.   "message_type": "incoming",
  6.   "content_type": null,
  7.   "content_attributes": {},
  8.   "source_id": null,
  9.   "sender": {
  10.     "id": 0,
  11.     "name": "contact-name",
  12.     "avatar": "",
  13.     "type": "contact"
  14.   },
  15.   "inbox": {
  16.     "id": 0,
  17.     "name": "API Channel"
  18.   },
  19.   "conversation": {
  20.     "additional_attributes": null,
  21.     "channel": "Channel::Api",
  22.     "id": 0,
  23.     "inbox_id": 0,
  24.     "status": "open",
  25.     "agent_last_seen_at": 0,
  26.     "contact_last_seen_at": 0,
  27.     "timestamp": 0
  28.   },
  29.   "account": {
  30.     "id": 1,
  31.     "name": "API testing"
  32.   },
  33.   "event": "message_created"
  34. }




Client APIs

Leverage Bevatel's client APIs to create customized customer interfaces, including chat widgets, mobile app integrations, platform extensions, for efficient customer data and interaction management.

Create Interfaces using 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 Bevatel.

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

  1. Use a custom chat interface instead of the Bevatel chat widget
  2. Build conversational interfaces into your mobile apps
  3. Add Bevatel to other platforms for which Bevatel 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.



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


Connecting to the Bevatel WebSockets

To receive real-time updates from the agent dashboard, You can connect to the Bevatel WebSockets. Bevatel WebSockets connecting can be made at the following URL

  1. <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-created API call.


Example


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


    • Related Articles

    • Whatsapp API

      Connecting to WhatsApp API via Embedded Signup: Step-by-Step Guide Step 1: Choose Channel Navigate to Channels: On the left menu, select Settings, then Channels. Select WhatsApp API as the channel. Click Continue to proceed with connecting via ...
    • Add Channels

      "Connect your website and social media accounts like Facebook, Twitter, WhatsApp, and more with Bevatel by adding inboxes. Access this feature through Welcome/onboarding, Settings, or your home screen Add Channels An Inbox connects your website, or ...
    • Telegram

      Setting Up Telegram Channels in Bevatel Effortlessly set up a Telegram channel in Bevatel by following simple steps, including creating a Telegram bot and adding agents, enabling efficient communication with your audience. How to create a Telegram ...
    • Contacts

      "Use date and source filters. Contacts Chart tracks changes, Contact Source shows acquisition channels, and Contact Logs offer detailed activity records." Frequency and date — Select a date range from the drop-down list to be applied to the report. ...
    • Dialogflow_Integration

      Objective: Integrate Bevatel with Dialogflow to leverage chatbots for automated responses and seamless agent handoffs, enhancing customer support capabilities. Why Integrate Bevatel with Dialogflow? Chatbots are an essential component of any customer ...