logo

Method of Accessing WeChat via Messaging Interface

I. Overview

When binding the URL and Token of other developers in the WeChat Developer Backend, if you want to simultaneously use Udesk services, you can achieve this by docking with the Udesk messaging interface through a server.

By docking with the Udesk messaging interface server, both message reception and sending go through the server. (For WeChat, special optimizations have been made. Images that comply with WeChat specifications can be directly generated by obtaining a token without the need for the server to upload to WeChat again.)

Administrators log in to the Udesk backend [Management Center - Instant Messaging - Message Interface Access]

udesk

II. Test whether the message reception channel is normal

Test whether the interface is unblocked:

curl https://xxxx.udesk.cn/spa1/im_callback/test?number=13574221234&email=894733082@qq.com&timestamp=20151124141451&sign=07131700A29AD987F5D9F0463CE7EFC7

Incoming parameters

number=13574221234&email=894733082@qq.com&timestamp=20151124141451&sign=07131700A29AD987F5D9F0463CE7EFC7

Parameter Description

Parameter NameDescription
numberPhone number
emailEmail
timestampTimestamp
signResult of generating md5 based on the previous parameters

Sign Generation Method

  • sign = md5(number=13574221234&email=894733082@qq.com&timestamp=20151124141451&secret).upper
  • Convert to uppercase after md5
  • secret: Corresponding to the "KEY" of the message push server address in [Management Center - Instant Messaging - Message Interface Access]

Return parameters

Success: { "success": true }
Failure:
{
  "success": false,
  "msg": "sign verification failed"
}
Parameter NameDescription
successTrue/false, request successful/failed
msgResult explanation in string format

III. Receiving Message Interface

Customer sends a message to customer service

1. Receiving Text Messages

Receiving Message Interface

POST http://xxxx.udesk.cn/spa1/im_callback?number=13574221234&email=894733082@qq.com&timestamp=20151124141451&sign=07131700A29AD987F5D9F0463CE7EFC7

Request Parameters (Request Body) Example

<xml>

  <FromUserName>openid</FromUserName>

  <Number>phone number</Number>

  <Email>894733082@qq.com</Email>

  <Content>this is a test</Content>

  <CreateTime>1548348776</CreateTime>

  <MsgType>text</MsgType>

  <MsgId>1548348777</MsgId>

</xml>

Parameter Description

Parameter NameDescription
FromUserNameSender account (an OpenID)
NumberCustomer mobile number or phone
EmailCustomer email
ContentMessage content
CreateTimeMessage creation time (integer)
MsgTypetext
MsgIdMessage ID, 64-bit integer

2. Receiving Image Messages

Receiving Message Interface

POST http://xxxx.udesk.cn/spa1/im_callback?number=13574221234&email=894733082@qq.com&timestamp=20151124141451&sign=07131700A29AD987F5D9F0463CE7EFC7

Request Parameters (Request Body) Example

<xml>

 <FromUserName><![CDATA[fromUser]]></FromUserName>

 <Number>phone number</Number>

 <Email>894733082@qq.com</Email>

 <CreateTime>1348831860</CreateTime>

 <MsgType><![CDATA[image]]></MsgType>

 <PicUrl><![CDATA[this is a url]]></PicUrl>

 <MediaId><![CDATA[media_id]]></MediaId>

 <MsgId>1234567890123456</MsgId>

 </xml>

Parameter Description

Parameter NameDescription
FromUserNameSender account (an OpenID)
NumberCustomer mobile number or phone
EmailCustomer email
CreateTimeMessage creation time (integer)
MsgTypeimage
PicUrlImage link
MediaIdMedia ID of the image message, can be used to call the multimedia file download interface to pull data.
MsgIdMessage ID, 64-bit integer

3. Receiving Voice Messages

Receiving Message Interface

POST http://xxxx.udesk.cn/spa1/im_callback?number=13574221234&email=894733082@qq.com&timestamp=20151124141451&sign=07131700A29AD987F5D9F0463CE7EFC7

Request Parameters (Request Body) Example

<xml>

 <FromUserName><![CDATA[fromUser]]></FromUserName>

 <Number>phone number</Number>

 <Email>894733082@qq.com</Email>

 <CreateTime>1357290913</CreateTime>

 <MsgType><![CDATA[voice]]></MsgType>

 <MediaId><![CDATA[media_id]]></MediaId>

 <Format><![CDATA[Format]]></Format>

 <MsgId>1234567890123456</MsgId>

</xml>

Parameter Description

Parameter NameDescription
FromUserNameSender account (an OpenID)
NumberCustomer mobile number or phone
EmailCustomer email
CreateTimeMessage creation time (integer)
MsgTypeVoice is voice
MediaIdMedia ID of the image message, can be used to call the multimedia file download interface to pull data.
FormatVoice format, amr
MsgIdMessage ID, 64-bit integer

4. Response Result When Receiving Messages

Parameter Description

Parameter NameDescription
statusCustomer service status, queuing/chatting/offline/unknown (queueing/chatting/offline/unknown error)
turnPosition in the queue
agent_nameCustomer service name
msgstring format message

Example

{
    "status": "chatting",
    "turn": 0,
    "agent_name": "Test Customer Service 1",
    "msg": "Test Customer Service 1 is serving you!"
}