Skip to main content

Create Session

Create one session.

Request

POST https://apichat.twt.com/openapi/chat/create_gd

Header Parameters

ParameterTypeRequiredDescription
x-chat-signaturestringYesHMAC-SHA256 signature. Calculate hash_hmac('sha256', raw_body, app_secret) with the exact raw JSON body
AcceptstringNoDefault: application/json
Content-TypestringYesapplication/json

Body Parameters

ParameterTypeRequiredDescription
appidstringYesApplication identifier from the console
timestampintegerYesRequest timestamp. In production, expired timestamps may be rejected
ranstrstringYesRandom string
sbsstringYesUnique customer identifier, 1 to 64 characters. The customer is created when it does not exist
ipstringYesCustomer IP address
sbs_mcstringYesCustomer name, 1 to 30 characters
contentstringYesInitial message, 1 to 2000 characters. This message is sent as the responsible agent
titlestringNoSession title, 1 to 120 characters. When provided, it is used as the visitor and agent remark title
kefu_idarray[integer]YesAgent ID list. Multiple agents are allowed
fzr_uidintegerYesResponsible agent ID. It must be included in kefu_id

Request Example

curl --location --request POST 'https://apichat.twt.com/openapi/chat/create_gd' \
--header 'x-chat-signature: 0bf19198ab2dd65a407ca8d57fbb3f6ebca71d22709a1f5d53c685e9e25abdbc' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
"appid": "42d7c13c16e7ed0479f2418eb8894310",
"timestamp": 1781683144,
"ranstr": "codex1033048655",
"sbs": "customer_001",
"kefu_id": [
10411,
10427
],
"fzr_uid": 10411,
"ip": "127.0.0.1",
"sbs_mc": "Customer Name",
"content": "Initial message",
"title": "Order Consultation"
}'

Response

200 Success

ParameterTypeRequiredDescription
codeintegerYes1 success, -1 failure
msgstringYesResponse message
data.chat_idintegerYesCreated session ID
{
"code": 1,
"msg": "ok",
"data": {
"chat_id": 900220
}
}

Error Example

{
"code": -1,
"msg": "token验证失败!",
"data": ""
}
{
"code": -1,
"msg": "参数错误",
"data": ""
}

Notes

  • The content field is required and is sent by the responsible agent specified by fzr_uid.
  • The title field is optional. When provided, it is saved as the visitor and agent remark title, while automatic title summarization continues as usual.
  • fzr_uid must be one of the agent IDs in kefu_id.
  • Agents other than fzr_uid are added as session participants.
  • The signature must be calculated from the exact raw JSON body sent in the HTTP request.