Last updated on Jun 27

2 min read

Chat API

Build modern chat and messaging experiences with Samespace Chat API. An easy to use chat API helps you to initiate a session and send messages.

Initiate a session

Create a session with the given attributes and return a unique id for the session.

Method POST
URL https://clusterId.samespace.com/chat/api/v2/initiate
Content-Type: application/json
{
 "id": "62984b25150c80786930ec74",
 "space_id": "alpha",
 "team_name": "helpdesk",
 "attributes": {
     "name": "Tom",
     "email": "[email protected]"
 },
 "webhook": "https://api.example.com/v1/message",
 "authorization": {
     "x-api-key": "Nr5ux@9D4EH!rhp2O9GuuC#S#d@qlu8R"
 }
}

Data Fields

  • id: External Visitor Identifier
  • space_id: Unique domain of Samespace
  • team_name: Samespace team name
  • attributes: The details you would like your agent to see, example name, email, company and more
  • webhook: A webhook is used to send real-time data from your flow to an external application whenever a given event occurs.
  • authorization : Authenticate your webhook

Response

{
   "uuid":"54a25666-e235-11ec-8fea-0242ac120002"
}

Send Message

Method POST
URL https://clusterId.samespace.com/chat/api/v2/message
Content-Type: application/json
{
 "uuid": "54a25666-e235-11ec-8fea-0242ac120002",
 "message": {
   "id": "54633839329460",
   "text": "Connect me to sales",
   "attachments": [
     {
       "name": "sample file",
       "type": "image/png",
       "url": "https://example.com/sample.png"
     }
   ]
 },
 "type": "message"
}

Data Fields

  • message: Contains text you want to send in the chat session
  • type : Event type can be one of typing, typing_end, message or end

Response

{success: "true",mid:  "54633839329460"}

Webhook Events

Content-Type: application/json
{
   "type": <event_name>,
   "uuid": "54a25666-e235-11ec-8fea-0242ac120002",
   "profile": {
        "name": "Tom",
        "photo_url": ""
    },
   "message": {
       "id": "54633839329460",
       "text":   "Connect me to sales",
       "attachments": [
           {
               "name": "sample file",
               "type": "png",
               "url": "https://example.com/sample.png"
             }        
       ]
    }
}

Data Fields

  • type: Event type can be onboard, left, typing, typing_end, message or end
  • uuid: Unique id of a session
  • profile: Samespace Live Agent/Bot
  • message: Receive message for ongoing session