To send messages to API channel, you need have a basic understanding of the models and nomenclature used in Chatwoot. Let us try to understand these first.
Channel: Channel defines the type of the source of conversations. Eg: Facebook, Twitter, API etc.
Inbox: You can create multiple sources of conversations which is of the same channel type. For eg: You can have more than one Facebook page connected to a Chatwoot account. Each page is called as the inbox in Chatwoot.
Conversation: A Conversation is a collection of messages.
Contact: Each conversation has a real life person associated with it, this person is called a contact.
Contact Inboxes: This is the session for each contact on a inbox. A contact can have multiple sessions and multiple conversations in the same inbox.
To send a message in an API channel, you have to create a contact, then create a conversation and then send a message.
api_access_token in the request header. You can get this token by visiting your Profile settings > Access Token
API documentation: (https://www.chatwoot.com/developers/api/#operation/contactCreate)
Pass the inbox id of the API channel along with other params specified. This would create a session for you automatically. A sample response would look like the one below.
As you can see in the payload, you will be able to see the
contact_inboxes and each
contact_inbox will have a
source_id. Source Id can be seen as the session identifier. You will use this source_id to create a new conversation as defined below.
API documentation: (https://www.chatwoot.com/developers/api/#operation/newConversation)
source_id received in the previous API call.
You will receive a conversation id which can be used to create a message.
API documentation: (https://www.chatwoot.com/developers/api/#operation/conversationNewMessage)
There are 2 types of messages.
Incoming: Messages sent by the end user is classified as an incoming message.
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.
If everything is sucessful 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. You can read about the message payload here