Updated on 2023-12-19 GMT+08:00

Sending a Message (send)

Scenario

This interface is invoked to send a channel message (such as a connection, sending input status, session, transfer-to-manual, or disconnection message).

Method

POST

URI

https://Domain name/apiaccess/ccmessaging/send (For example, the domain name is https://service.besclouds.com.)

Request Description

Table 1 Request header parameters

No.

Parameter

Type

Mandatory or Not

Description

1

ccmessaging-token

String

Yes

Value of ccmessaging-token generated by the applyToken interface

2

x-app-key

String

Yes

App key, which is the user ID and is configured on the API Fabric

3

Authorization

String

Yes

Authentication field. The format is Bearer {Value of AccessToken returned by the tokenByAkSk interface}. (A space is required after Bearer.)

Table 2 Request body parameter

No.

Parameter

Type

Mandatory or Not

Description

1

reqBody

sendMsgReq

Yes

Request body

Table 3 sendMsgReq parameters

No.

Parameter

Type

Mandatory or Not

Description

1.1

channel

String

Yes

Type of the channel through which the client sends a message, for example, the web channel (web customer service access channel)

1.2

content

String

No

Message content, which varies depending on mediaType. For example, if mediaType is set to TEXT, the value is the text content to be sent. The size of the text content to be sent cannot exceed 1 KB. If mediaType is set to audio, video, or other media types, the value is in the format of fileId,mediaType, where fileId indicates the value of objectKey returned by the /ccmessaging/uploadFileStream interface. The value is value of objectKey,jpg for images, value of objectKey,mp4 for videos, value of objectKey,mp3 for audio, and value of objectKey,txt for locations. The file download interface uses fileId to download a file.

If mediaType is set to WEBCARD, the value is a string converted from the JSON structure. For example, the fixed JSON structure is as follows:

{"title":"Card title","description":"Card description","mediaFileId":"Card media file ID (which is returned by the upload interface)","mediaFileType":"Only fixed values img, img/png, and img/jpg are supported. If this parameter is left empty, the default value jpg is used.","redirectUrl":"Redirection URL"}

Either redirectUrl or mediaFileId must be set. Other parameters can be left empty. For details, see the example of sending a web card message to an agent.

1.3

controlType

String

Yes

Message control type. The options are CONNECT, CHAT, TRANS2AGENT, INPUT, DISCONNECT, and READ.

1.4

from

String

Yes

ID of the user who sends a message through a channel

1.5

mediaType

String

Yes

Message media type. The options are TEXT, IMAGE, AUDIO, VIDEO, FILE, FILE_IMAGE, FILE_VIDEO, WEBCARD, and LOCATE.

1.6

senderNickname

String

No

Nickname of the message sender

1.7

sourceType

String

Yes

Message source type. Set this parameter to CUSTOMER.

1.8

timestamp

String

No

Time when a message is sent

1.9

to

String

Yes

Channel configuration ID

1.10

userAgent

String

No

User client type, which is obtained from UserAgent

1.11

senderAvatar

String

No

Avatar of the message sender. For the WeChat channel, the WeChat avatar URL is transmitted.

1.12

messageId

String

No

Unique ID of the user who sends the message. The value can contain a maximum of 32 characters. The value cannot contain commas (,).

1.13

transData

String

No

Data in JSON format, which is transferred to the robot flow when the robot is connected

Response Description

  • Status code: 200
    Table 4 senMsgRsp parameters

    No.

    Parameter

    Type

    Mandatory or Not

    Description

    1.1

    resultDesc

    String

    No

    Result code description.

    The description varies depending on the scenario.

    • CONNECT message for connecting to an agent

      If resultCode is 0, the operation is successful.

      If resultCode is 11, the description is Queuing...

      If resultCode is 12, the description is The current time is not within the working time of the service agents.

      If resultCode is 13, the description is No ccucs address available! or connect failed, none channel config found.

      For other non-0 errors, see "Error Code Reference" in CCUCS Interface Developer Guide.

    • CONNECT message for connecting to the robot

      If resultCode is 0, the description is connect to robot successfully or process robot multi message successfully.

      If resultCode is 11, the description is Queuing...

      If resultCode is 13, the description is Failed to disconnect robot, No ccucs address available!, fail to initialize robot., or connect failed, none channel config found.

    • DISCONNECT message for disconnecting from an agent

      If resultCode is 0, the description is disconnect successfully.

      If resultCode is 11, the description is Queuing...

      If resultCode is 13, the description is disconnect failed., disconnect failed, none channel config found., or disconnect failed, session keep touch failed.

    • DISCONNECT message for disconnecting from the robot

      If resultCode is 0, the description is Disconnect robot successfully.

      If resultCode is 11, the description is Queuing...

      If resultCode is 13, the description is Failed to disconnect robot., disconnect failed, none channel config found., or disconnect failed, session keep touch failed.

    • CHAT message for chatting with an agent

      If resultCode is 0, the description is sendUserMessage successfully.

      If resultCode is 3, the description is Incorrect JSON format, content can not be empty, the content Json String must contains mediaFileId or redirectUrl, the content Json String must contains title, or Incorrect mediaFileType.

      If resultCode is 11, the description is Queuing...

      If resultCode is 13, the description is sendUserMessage failed., Chat failed because the content is empty., chat failed, none channel config found., or chat failed, send too quick or session keep touch failed.

    • CHAT message for chatting with the robot

      If resultCode is 0, the description is Failed to disconnect robot, Send message to robot successfully, or process robot multi message successfully.

      If resultCode is 3, the description is Incorrect JSON format, content can not be empty, the content Json String must contains mediaFileId or redirectUrl, the content Json String must contains title, or Incorrect mediaFileType.

      If resultCode is 11, the description is Queuing...

      If resultCode is 13, the description is connect failed, Chat failed because the content is empty., chat failed, none channel config found., or chat failed, send too quick or session keep touch failed.

    • TRANS2AGENT message

      If resultCode is 13, the description is transfer to agent failed, none channel config found.

      If resultCode is 13, the description is fail to transfer from robot to agent,session keep touch failed.

      If resultCode is 13, the description is fail to transfer from robot to agent,it has been agent service.

      If resultCode is 11, the description is Queuing...

      If resultCode is 12, the description is The current time is not within the working time of the service agents.

      If resultCode is 13, the description is fail to transfer from robot to agent,connect to ccucs failed.

      If resultCode is 13, the description is Failed to disconnect robot.

      If resultCode is 0, the description is transfer from robot to agent success.

    • INPUT message

      If resultCode is 0, the description is sendUserMessage successfully.

      If resultCode is 11, the description is Queuing...

      If resultCode is 13, the description is send inputStatus failed, none channel config found.

      If resultCode is 13, the description is This is robot service,this message is prevented!

      If resultCode is 13, the description is sendUserMessage failed.

      If resultCode is 13, the description is Queuing...

      If resultCode is 3, the description is as follows:

      The redirection address is not in the trust list, contact operation staff to add it.

    1.2

    resultCode

    String

    Yes

    Interface return code. The value 0 indicates success, and other values indicate failure.

    1.3

    offlineMsg

    Object

    No

    If the offline function is enabled, the value is true. If the offline function is disabled, the AICC does not return this object.

    1.3.1

    isOfflineStatus

    Boolean

    No

    This parameter is used by the client to determine whether the user can send messages after the connection fails.

    This parameter is used in the following scenarios:

    1. The user fails to send a message whose controlType is CONNECT.

    2. The user fails to send a message whose controlType is CHAT. No session exists.

    3. The user sends a message whose controlType is DISCONNECT when waiting in a skill queue.

    1.3.2

    tipText

    String

    No

    If isOfflineStatus is true, the offline mode is triggered, and the message is saved.

  • Status code: 400

    Incorrect request. Check the request path and parameters.

  • Status code: 401

    Unauthorized operation. 1. Check whether you have purchased related services. 2. Contact customer service to check the status of your account.

  • Status code: 404

    The requested content is not found. Check the request path.

  • Status code: 500

    Business failure. Check the values of parameters in the request.

Error Codes

None

Example

  • Scenario: Send a request for connecting to the robot.

Request parameters:

{
  "content": "",
  "controlType": "CONNECT",
  "from": "session_1619573111751_user_1619573111751",
  "mediaType": "TEXT",
  "senderNickname": "user_1619573111751",
  "sourceType": "CUSTOMER",
  "timestamp": "1619573122352",
  "to": "1011577355744904195",
  "userAgent": null,
  "senderAvatar": null,
  "channel": "WEB"
}

Response parameters:

{
    "resultCode": "0",
    "resultDesc": "connect to robot successfully."
}
  • Scenario: Send a request for chatting with a robot.

Request parameters:

{
  "content": "Version",
  "controlType": "CHAT",
  "from": "session_1619573111751_user_1619573111751",
  "mediaType": "TEXT",
  "senderNickname": "user_1619573111751",
  "sourceType": "CUSTOMER",
  "timestamp": "1619573123199",
  "to": "1011577355744904195",
  "userAgent": null,
  "senderAvatar": null,
  "channel": "WEB"
}

Response parameters:

{
    "resultCode": "0",
    "resultDesc": "Send message to robot successfully"
}
  • Scenario: Send a request for switching from robot service to manual service.

Request parameters:

{
  "content": "",
  "controlType": "TRANS2AGENT",
  "from": "session_1619573111751_user_1619573111751",
  "mediaType": "TEXT",
  "senderNickname": "user_1619573111751",
  "sourceType": "CUSTOMER",
  "timestamp": "1619573129953",
  "to": "1011577355744904195",
  "userAgent": null,
  "senderAvatar": null,
  "channel": "WEB"
}

Response parameters:

{
    "resultCode": "0",
    "resultDesc": "transfer from robot to agent success."
}
  • Scenario: Send a web card message to an agent.

Request parameters:

{
  "content": "{\"title\":\"Test title\",\"description\":\"Test description\",\"mediaFileId\":\"xxxx-xxxx-xxxx-xxxx-2e171ac78313\",\"mediaFileType\":\"img\",\"redirectUrl\":\"https://www.****.com\"}",
  "controlType": "CHAT",
  "from": "session_1619573111751_user_1619573111751",
  "mediaType": "WEBCARD",
  "senderNickname": "user_1619573111751",
  "sourceType": "CUSTOMER",
  "timestamp": "1619573129953",
  "to": "1011577355744904195",
  "userAgent": null,
  "senderAvatar": null,
  "channel": "WEB"
}

Response parameters:

{
    "resultCode": "0",
    "resultDesc": "sendUserMessage successfully."
}
or 
{
    "resultCode": "3",
    "resultDesc": "The redirection address is not in the trust list, contact operation staff to add it."
}
  • Scenario: Send a disconnection request.

Request parameters:

{
  "content": "",
  "controlType": "DISCONNECT",
  "from": "session_1619573842490_user_1619573842490",
  "mediaType": "TEXT",
  "senderNickname": "user_1619573842490",
  "sourceType": "CUSTOMER",
  "timestamp": "1619573854156",
  "to": "1011577355744904195",
  "userAgent": null,
  "senderAvatar": null,
  "channel": "WEB"
}

Response parameters:

{
    "resultCode": "0",
    "resultDesc": "Disconnect robot successfully"
}