发送liveChat请求

发送请求,开启或关闭liveChat

用户可以在whatsapp上进行智能对话或进行人工对话。当需要人工对话时,Botchat发起开启livechat(状态)请求;若太久未有人工接通,则botchat可发送关闭liveChat(状态)请求;而如果等待到真正接起人工时,livechat向botchat发送start_licechat信号,通知其已接通人工,不用再理会用户的操作;当人工对话结束时livechat向botchat发起关闭liveChat(状态)请求,继续进行智能对话。

chat status

发送请求

您可以用任意一个已经启用的API Key(怎样申请APIKey) 向Moli发起关闭liveChat请求、向Bot发起开启livechat请求。这个请求的说明如下:

请求属性 属性名 说明
地址 https://api.bothub.ai/channels/{bot_phone}/switch_livechat
请求方式 POST
Header APIKEY 您的API KEY.
Header Content-Type application/json
Form Data id 由WhatsApp分配的消息ID
Form Data user_id 用户的手机号
Form Data source 信号来源(botchat/livechat)
Form Data signal 信号(start_livechat或stop_livechat)
Form Data meta 先决条件信息 json (当signal为start_livechat时为必须)

请求样例

{
    "id" : "<unique request identifier>",
    "user_id" : "<phone number of the user>",
    "source" : "<botchat / livechat>",
    "signal" : "<start_livechat / stop_livechat>",
    "meta" : {
        "selected_email" : "<email of the user>"
    }
}

请求返回值

  • 成功返回值样例
{
    "result": true,
    "data": {}
}
  • 失败返回值样例
{
    "error": {
        "code": 10011,
        "error_subcode": 0,
        "type": "",
        "message": "Request already processed",
        "request_id": 35122312158
    }
}

错误码列表

返回值 内容
10000 内部错误
10001 未指定API KEY
10002 无效的API KEY
10003 未指定Request id
10004 未指定调用API的种类
10005 无效的API种类
10005 无效的API种类
10006 Bot不存在或者已经被删除
10011 Request id与之前的重复
10100 参数无效
18000 内部错误
19000 回调超时
41006 未指定id
41026 未指定user_id
41027 未指定signal
41033 未指定meta
41034 meta类型错误,应为json
41035 未指定source
41036 source值错误,应为botchat/livechat
90001 livechat subscriber error
90002 network error
90003 livechat请求不在人工作息时间内

接口会给subscriber发送信息

不同subscriber发送信息样式不同。

请求属性 属性名 说明
Form Data id 消息ID
Form Data country 城市
Form Data email 邮箱
Form Data ts 信息发送时间的时间戳
Form Data meta 最近30分钟的对话(当subscriber mode为pcsd时才传该变量)

请求样例

{
    "id":"<unique message identifier>",
    "country":"in",
    "email":"<the email>",
    "ts":"<the timestamp>",
    "meta":{
        "conversations":[
            {
                "id":"<unique message identifier>",
                "from":"<phone number of the sender user>",
                "to": "<phone number of the recipient user>",
                "timestamp":"<the timestamp of sending message>",
                "type":"text",
                "text":{
                    "body":"hi"
                }
            },
            {
                "id":"<unique message identifier>",
                "from":"<phone number of the sender user>",
                "to": "<phone number of the recipient user>",
                "timestamp":"<the timestamp of sending message>",
                "type":"image",
                "image":{
                    "url": "<your-media-url>",
                    "caption": "<your-image-caption>",
                    "extension": "<see the list of available extensions>"
                }
            }
        ]
     }
}

results matching ""

    No results matching ""