Fetching chat conversations
Overview¶
Giosg platform provides APIs for fetching chat conversations and all related metadata. The first section guides you through which endpoints to use to fetch the chats, chatlogs and metadata. The second part of this guide helps you to setup a notification service to get notified when a chat ends. The third part is covering encryption and decryption of chat conversations in giosg.
Prerequisites¶
Access token:
Get API token for authentication
Api tokens can be created here: Log in to Console → Settings Menu → Company → Access tokens
Once you have obtained your API tokens, define the Authorization HTTP header for all your API requests:
1 |
|
You should replace the <api_key>
with your API tokens
Note
Remember that the api-token is connected to the user that created the token which means that if the user is deleted also the token is invalidated. You can create an extra user and create the token with this user, remember to name the user so that it doesn’t get deleted by mistake e.g “Reporting api-user do not delete”
Generic authorization function that can be used for all endpoints described below¶
You may use below functions for all Javascript and Python calls to handle the authorization and the request
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Fetching the chats¶
First you need to decide which chat conversations you want to fetch. This could be all organization's chats or chats for specific giosg Rooms
.
- First you need to decide which chat conversations you want to fetch.
- This could be all organization's chats or chats for specific
giosg Room
. In the below examples the chats are listed for the whole organization. Endpointhttps://service.giosg.com/api/v5/orgs/<organization_id>/owned_chats
lists all the chats for the organization.
Please check List organization's owned chats API for more information what filters you can apply when querying the chats.
1 2 3 4 5 6 |
|
1 2 3 4 5 6 |
|
Fetching the chats per room¶
You can order the chats to show from newest to oldest and only include chats with messages by adding query parameters:
?ordering=-created_at&has_user_messages=true&has_visitor_messages=true
.
Fetching open chats and ending them¶
If you are using external
type of chats which are not ended automatically you might end up in old open chats. To handle these ghost chats you can use the APIs to fetch and end them. First you have to specify what is the time frame you want to wait before ending a chat (for example 1 week or 1 month).
You can fetch open chats by using these query parameters
?ordering=-created_at&is_ended=false
.
Then you can check the updated_at
field to check when the chat has been updated. If it has not been updated in a time frame you've specified you can end the chat.
See List chats at a room API and List organization's owned chats API.
Listing the messages for a chat¶
When you have all the chats listed you can get the messages by looping through the result from the owned chats response for every chat id using this endpoint:
/api/v5/orgs/<organization_id>/owned_chats/<chat_id>/messages
1 2 3 4 5 6 7 |
|
1 2 3 4 5 6 7 8 |
|
Memberships¶
If you need to know who has been involved in the chat you can get the memberships for each chat with this endpoint:
/api/v5/orgs/<organization_id>/owned_chats/<chat_id>/memberships
Hint: Store the member id for the visitor if you use visitorvarialbes so that you can use it for fetching the variables set in the chat.
1 2 3 4 5 6 7 |
|
1 2 3 4 5 6 7 8 |
|
Fetch visitor data for a chat¶
GET /api/v5/orgs/<organization_id>/owned_chats/<chat_id>/visitors/<visitor_id>/variables
See List chat visitor variables API
The visitor id you need to pass in this api-call stored chat membership call can be used used here
1 2 3 4 5 6 7 8 |
|
1 2 3 4 5 6 7 8 9 |
|
Listing tags used in a chat¶
GET /api/v5/orgs/<organization_id>/owned_chats/<chat_id>/tags
1 2 3 4 5 6 7 |
|
1 2 3 4 5 6 7 |
|
Get notifications about an ended chat (optional)¶
If you would like to get a notification every time a chat ends and then fetch the messages for it you could configure a new Giosg App from "Settings" -> "Apps" -> "Add new app".
Only thing you need to configure in this app is the basic information like name, description, the app trigger url (This is the url of your server which gets called) and the trigger event that in your case would be "Run on background when chat ends" (see below screenshot).
When the app is configured and installed you will get an http get request to the configured url.
Trigger setup¶
App trigger setup
Conclusion¶
In the first part of the tutorial we showed you what endpoints and rest-api calls you can use to fetch chats and metadata connected to them. The second part guided you through the process of adding notifications about ended chats.
Endpoins used in this tutorial¶
List organization's owned chats API