Chats API
Chat API¶
Chats¶
A chat represents a single conversation. In practice, there is usually zero or one visitor member and an arbitrary number of user ("operator") members.
A chat has the following attributes:
| Attribute | Type | Editable | Description | 
|---|---|---|---|
| id | UUID | read-only | Unique identifier for the chat | 
| token | string | read-only | A legacy Giosg-signed encoded unique string for the chat | 
| created_at | datetime | read-only | When the chat conversation started | 
| updated_at | datetime | read-only | When the chat conversation was last time updated | 
| is_waiting | boolean | read-only | This is truefor new chats that are started by a visitor and they require a response by a user (and the chat has not ended yet). Otherwise this isfalse. | 
| waiting_started_at | datetime | read-only | When the chat became waiting. This is the timestamp when the is_waitingattribute changedtrue. It does not change when theis_waitingbecomesfalse. Default value for this isnulland it stays so if the chat never became waiting. | 
| is_ended | boolean | optional | Whether or not the chat has ended. Once ended, messages and members of the chat cannot be altered any more. Updating this to trueimmediately and permanently locks the chat. Defaults tofalse. | 
| ended_at | datetime | read-only | When the chat conversation ended (or nullif not yet ended) | 
| room_id | UUID | read-only | ID of the room in which the chat occurred | 
| chat_type | string | optional | Whether the chat's type is visitor ( visitor), or task (task) or from some external source (external). When POSTing a new chat with create a new chat endpoint this will default tovisitorif omitted from request. Chats with typevisitorare chat sessions that has a visitor membership. Chats with typetaskwill be closed automaticaly by room options ttl. Chats with typeexternalare chat sessions that are from external source (e.g. some integration). These chat's do not close automatically. | 
| is_autosuggested | boolean | read-only | Whether or not the chat started with an autosuggestion | 
| is_encrypted | boolean | read-only | Whether or not the messages of this chat are stored encrypted. | 
| message_count | integer | read-only | How many messages there are in total in this chat at the moment. NOTE that this only includes messages with type msg, so this does not include autosuggestions, or join/leave messages. | 
| user_message_count | integer | read-only | How many messages there were by operator in this chat | 
| visitor_message_count | integer | read-only | How many messages there were by visitor in this chat | 
| member_count | integer | read-only | How many people (visitor and users) have attended or sent messages to this chat. | 
| user_member_count | integer | read-only | How many users have sent at least one message to the chat. | 
| visitor_member_count | integer | read-only | How many visitors have attended this chat. | 
| present_participant_count | integer | read-only | How many people (visitor and users) there are currently participating and present at this chat. | 
| present_user_participant_count | integer | read-only | How many users there are currently participating and present at this chat. | 
| present_visitor_participant_count | integer | read-only | How many visitor there are currently participating and present at this chat | 
| visitor_wait_time | float | read_only | How many seconds the visitor had to wait for an answer to the first sent message. This is nullif the visitor has not got an answer yet. | 
List visitor's chats¶
You can get a list of all chats of the visitor.
| 1 |  | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |  | 
GET /api/v5/public/visitors/<visitor_id>/chats
This API endpoint returns a paginated collection. They are sorted by the creation time of the chats, in ascending order.
Retrieve visitor's chat¶
Get a single chat object by its ID.
GET /api/v5/public/visitors/<visitor_id>/chats/<chat_id>
Create a new chat¶
Start a new chat with a visitor in the given room.
POST /api/v5/public/orgs/<organization_id>/rooms/<room_id>/visitors/<visitor_id>/chats
The visitor will automatically be added as member of the chat by creating a Chat membership resource. This endpoint will attempt to get an existing open chat in this room where the visitor is already a member, instead of creating a new chat. This will update visitor's is_participating status.
You may want to start chat with a specific user or users. This endpoint can take user_member_ids list as payload. This will try to find existing chat for visitor and all the given users. user_member_ids list must contain only ID's of users who have access to this room.
You may also want to state that your chat is coming from some specific integration and you do not want giosg to automatically end the chat after two hours (e.g. you are using giosg's chat as a part of mailbox app in which the chats should persist). You may set chat_type to be external instead of visitor. This however leaves the responsibility of closing the chat for the integration provider or for operators via giosg console. If the chats are not closed then they won't show as proper chat sessions in giosg's reporting.
This endpoint will return:
- 200 if existing open chat in this room for visitor was found and is_participatingstatus was updated.
- 201 when a new chat was created successfully.
- 400 if user_member_idslist was provided but the users were not found or the users do not have access to the room.
- 400 if chat_typewas provided but the choice was invalid.
End a chat¶
Example request that closes a chat
| 1 |  | 
Example payload
| 1 2 3 |  | 
Conversations between users and visitors usually end automatically when no one has sent any messages to the chat after a certain time. However, visitor may also explicitly end the chat conversation.
Once ended, no new chat messages or chat memberships can be added to the chat anymore! Chat cannot be reopened. You should create a new chat if you want to continue conversation with the other person.
You can end explicitly a chat in which you are a member by updating the is_ended attribute to true:
PUT /api/v5/public/visitors/<visitor_id>/chats/<chat_id>
or
PATCH /api/v5/public/visitors/<visitor_id>/chats/<chat_id>
You need to define the is_ended attribute with value true as a payload.
Chat memberships¶
The visitor and each user who has participated to a chat is added as a chat membership to the chat.
| Attribute | Format | Editable | Description | 
|---|---|---|---|
| member_id | UUID/string | read-only | ID of the user or visitor being present at the chat. | 
| member_type | string | read-only | Either visitororuser. | 
| member_public_name | string | read-only | The name of the user/visitor as it would be displayed for the visitor. This is user's alias if they have one, otherwise it is their real name. For visitors, this is any custom username (e.g. set by API data) or null | 
| member_avatar | object | read-only | If the user/visitor has an avatar image, then this is is an object with idandurlattributes. Otherwise this isnull. | 
| chat_id | UUID | read-only | ID of the chat. | 
| created_at | datetime | read-only | When the user/visitor was added as a chat member. | 
| last_seen_at | datetime | optional | When the user/visitor was last seen at. This field may be updated by clients to let other clients know that user has seen the conversation and messages were read. This field may be nullif the value was not set yet. | 
| updated_at | datetime | read-only | When the this membership was updated. | 
| message_count | integer | read-only | How many messages the user/visitor has sent to the chat. This may be 0, e.g. when operator has joined the chat but has not sent any message yet. | 
| is_participating | boolean | required | Whether or not the user/visitor has the chat "open". In practise this reflects the state of the chat window. When the user/visitor closes the chat window, it is supposed that he is no more participating the chat (but the membership still remains) | 
| is_present | boolean | read-only | Whether or not the user/visitor is currently present. Equals the is_presentattribute of the member. | 
| composing_status | string | required | One of the following: idle,typing,typed. Thetypingstatus will be automatically downgraded totypedif the composing status has not been refreshed for a while. | 
List chat memberships¶
| 1 |  | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |  | 
You may get a paginated collection of all memberships of a chat.
GET /api/v5/public/visitors/<visitor_id>/chats/<chat_id>/memberships
Returns 404 if the chat is not one of the visitor's chats.
List chat memberships of a visitor¶
As an alternative to list a visitor's chats, you can also list a visitor's chat memberships as a paginated collection. This includes each chat membership object that represents the visitor in each of his chats.
GET /api/v5/public/visitors/<visitor_id>/chat_memberships
Change visitor chat status¶
Example request for making the visitor typing at the chat
| 1 |  | 
Example request payload
| 1 2 3 4 5 |  | 
The participation status should be refreshed when the visitor opens or closes a chat. In addition, you should frequently notify the backend about the composing status of the visitor. For example, you should make a request when the visitor starts typing a message for the chat (and more requests frequently if the visitor keeps typing, stops typing or clears the composition area).
Also it is highly recommended that clients update last_seen_at field whenever user interface displays chat to user. This allows other clients to know if messages have been received and read/seen by the other users.
You can change the chat status of the visitor:
PUT https://service.giosg.com/api/v5/public/visitors/<visitor_id>/chat_memberships/<chat_id>
Chat messages¶
Chat consists of a number of messages. Some of them are actual typed messages from either operator or visitor, and some of them are automatically added events about the chat, especially when an operator has joined or leaved the chat.
| Attribute | Type | Editable | Description | 
|---|---|---|---|
| id | UUID | read-only | Unique identifier for the message | 
| type | string | required | Whether the message is an actual message ( msg), autosuggest (autosuggest), a join event (join), a leave event (leave), an action event (action), a call request (call_request), a call information (call_ended), a interaction data (interaction_submit), or a message from system (system). When POSTing a message, this can be set tomsg,action,call_request,interaction_submit, orsystem. | 
| chat_id | UUID | read-only | ID of the chat. | 
| created_at | datetime | read-only | When the message was sent | 
| sender_type | string | required | Whether the sender is operator ( user), visitor (visitor), or triggered by rule (rule). When POSTing a new message with these endpoints, this will accept onlyvisitorandruleas sender types. | 
| sender_id | UUID/string | optional | Identifier for the sender. If the sender is a user, then this is the user's ID. For visitor this is an unique string. If the sender was a rule, it is the ID of the rule which triggered this message. | 
| sender_public_name | string | read-only | A display name for the sender as the visitor would see the him. This value might change if the sender type was rule. Note: If themessage_typeisrule, then this field is required. | 
| sender_avatar | object | read-only | If the sender has an avatar image, then this is an object with idandurlattributes. Otherwise this isnull. | 
| message | string | required | Content text of the message. The maximum length is 4000 characters. This will always be the decrypted if the decryption key is still being stored at the server. Otherwise, this will be nullif the server cannot decrypt the message any more. In cases where the chat message'stypewasaction, this can be either thetextof the chosen attachment action ortitleof theattachment. If neither are provided, this isnull. Note: If the message'stypeisaction, then this field is read-only. | 
| is_encrypted | boolean | read-only | Whether or not the message is stored encrypted. If trueandmessageisnull, it means that the message cannot be decrypted anymore. | 
| attachments | list of objects | read-only | List of chat message attachments for this chat message. These represent rich or interactive content provided in this message. | 
| attachment_template | string | read-only | Type of chat message attachment template, either null,"generic"or"interaction". | 
| response_to_message_id | UUID | read-only | Unique identifier of the message this was a response to. nullif it wasn't a response. | 
| response_to_attachment_id | UUID | read-only | Unique identifier of the chosen attachment this was a response to. nullif it wasn't a response. | 
| response_to_attachment | object | read-only | The chosen attachment of the response. nullif it wasn't a response. | 
| response_to_action_id | UUID | read-only | Unique identifier of the chosen attachment action this was a response to. nullif it wasn't a response. | 
| response_to_action | object | read-only | The chosen attachment action of the response. nullif it wasn't a response. | 
| response_value | string | read-only | The chosen attachment value of the response. If the chosen attachment was an action, then this is thevalueof the action. Otherwise this may be theattachment'stitle_link_url,image_url,image_link_urlor a link provided intextfield (Markdown).nullif it wasn't a response. | 
| response_text | string | read-only | Response text of the attachment response. This field may be nullif response was togenericattachment or free form text if this message was response to interaction attachment. This field is required forinteractionattachment response. | 
List chat messages¶
| 1 |  | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |  | 
Get the collection of all chat messages in the given chat.
GET /api/v5/public/visitors/<visitor_id>/chats/<chat_id>/messages
Send a chat message¶
Example request for normal message
| 1 |  | 
Example request payload for normal message
| 1 2 3 4 |  | 
Send a new chat message with type msg to a chat:
POST /api/v5/public/visitors/<visitor_id>/chats/<chat_id>/messages
The sender_type is automatically set to visitor and sender_id is set to <visitor_id>.
If this is the first message with type msg in the chat, then its is_waiting attribute is automatically set to true. (This only affects the authenticated users)
This endpoint will return:
- 201 if a new chat message was created successfully
- 403 if the visitor has been banned
- 404 if the chat is not one of the visitor's chats
- 404 if the visitor does not exist
- 409 if the chat is ended
Example request for system message
| 1 |  | 
Example request payload for system message
| 1 2 3 4 5 6 7 |  | 
Send a new chat message with type system to a chat:
POST /api/v5/public/visitors/<visitor_id>/chats/<chat_id>/messages
The required parameters for this endpoint are:
- type, this has to be- system.
- sender_id, this should be the ID of the rule which triggered this message.
- sender_type, this has to be- rule.
- sender_public_name, this has to match rule action's send message's- sender_public_namefield. Note: This value is only obtainable from settings page currently.
- message, this has to match rule action's value. Note: This is only obtainable from settings page currently. Note: If rule action is- send interaction to chattype this has to match the interaction id.
This endpoint will return:
- 201 if a new chat message was created successfully
- 400 if there is no real Rule with the given sender_id
- 400 if typeandsender_typeare not both in correct formats
- 400 if the rule action's sender_public_nameand givensender_public_namediffer
- 400 the rule action's valueand givenmessagediffer
- 403 if the visitor has been banned
- 404 if the chat is not one of the visitor's chats
- 404 if the visitor does not exist
- 409 if the chat is ended
Reply to chat message attachment¶
There are some additional fields that need to be included in payload when the visitor reacts to the attachment. These fields are:
| Attribute | Type | Editable | Description | 
|---|---|---|---|
| type | string | required | Type of this message. This should be actionthis case. | 
| response_to_message_id | UUID | required | ID of the original message with attachments which the visitor reacted. | 
| response_to_attachment_id | UUID | required | ID of the attachment which the visitor reacted. | 
| response_to_action_id | UUID | optional | ID of the attachment action which the visitor reacted. In cases where the attachment does not have this field, it can be neglected. | 
| response_value | string | required | String representation of the attachment field ( title_link_url,image_url,image_link_urlor a link inside markdown) to which the visitor reacted. This should be omitted in cases where the visitor reacted to an action. Note: If the chosen attachment was anaction, then this field is read-only. | 
| response_text | string | optional | Response text of attachment response. This field is optional for generic chat attachments and required when replying to interaction attachment or external attachment. | 
Note: In cases where visitor sends a message of type action, the message field is NOT required!
| 1 |  | 
Example request payload
| 1 2 3 4 5 6 |  | 
Example response
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |  | 
Send a new chat message with type action to a chat:
POST /api/v5/public/visitors/<visitor_id>/chats/<chat_id>/messages
The basic concept for this is as same as sending a new chat message to the chat with different payload for type field. Note that you must also include the rest of the required fields.
Chat tags¶
List all tags used on visitor's chat. This API returns only hashed versions of tag names.
| Attribute | Format | Editable | Description | 
|---|---|---|---|
| hashed_name | string | read-only | Hash of the tag name added to visitor's chat. | 
| chat_session_id | UUID/string | read-only | ID of chat session this tag belongs to. | 
| room_id | UUID/string | read-only | ID of the room where chat session belongs to. | 
| created_at | datetime | read-only | When the tag was added to chat. | 
List chat tags¶
| 1 |  | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |  | 
You may get a paginated collection of all tags of a chat.
GET /api/v5/public/visitors/<visitor_id>/chats/<chat_id>/tags
Returns 404 if the chat is not one of the visitor's chats. Returns empty list if chat doesn't have any tags.
Chat queue¶
The Chat Queue API delivers information about the queue status for visitor chat.
| Attribute | Format | Editable | Description | 
|---|---|---|---|
| id | UUID/string | read-only | ID of the queue. | 
| chat_id | UUID/string | read-only | ID of chat session this queue belongs to. | 
| room_id | UUID/string | read-only | ID of the room where chat session belongs to. | 
| created_at | datetime | read-only | When the queue was added to chat. | 
| organization_id | UUID/string | read-only | ID of the organization the room belongs. | 
| type | string | read-only | Type of the queue. | 
| current_position_in_queue | integer | read-only | Visitors position in the queue. | 
| initial_estimated_wait_time | datetime | read-only | Initial waiting time estimation. | 
| current_estimated_wait_time | datetime | read-only | Updated waiting time estimation. | 
| chat_picked_up_at | datetime | read-only | Time when chat is picked up (for active queue object this is always null). | 
Retrieve chat queue¶
GET /api/v5/public/visitors/<visitor_id>/chats/<chat_id>/queue
Example response
| 1 2 3 4 5 6 7 8 9 10 11 12 |  | 
If no active queue object in the visitor chat or queue is not enabled in the room settings, API will return empty object.