# Receiving Messages and Events
Use <button open-type="contact" />
in the page to display the customer service session button.
When a user sends a message in a customer service session, or when an event is pushed due to certain operations performed by the user, the Weixin server will send the data package of the message or event to the URL configured by the developer. After receiving the request, the developer can respond to the request asynchronously via the Send Customer Service Messages API.
The followings are the structures of JSON and XML data packages via which various types of messages are pushed.
# Text Messages
The following data package is generated when the user sends text messages in a customer service session:
# In XML format
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1482048670</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[this is a test]]></Content>
<MsgId>1234567890123456</MsgId>
</xml>
# In JSON format
{
"ToUserName": "toUser",
"FromUserName": "fromUser",
"CreateTime": 1482048670,
"MsgType": "text",
"Content": "this is a test",
"MsgId": 1234567890123456
}
# Parameters
Parameter | Description |
---|---|
ToUserName | Mini Program's original ID |
FromUserName | Sender's openid |
CreateTime | Creation time of the message (integral) |
MsgType | text |
Content | Text message content |
MsgId | Message ID (64-bit integer) |
# Image Messages
The following data package is generated when the user sends image messages in a customer service session:
# In XML format
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1482048670</CreateTime>
<MsgType><![CDATA[image]]></MsgType>
<PicUrl><![CDATA[this is a url]]></PicUrl>
<MediaId><![CDATA[media_id]]></MediaId>
<MsgId>1234567890123456</MsgId>
</xml>
# In JSON format
{
"ToUserName": "toUser",
"FromUserName": "fromUser",
"CreateTime": 1482048670,
"MsgType": "image",
"PicUrl": "this is a url",
"MediaId": "media_id",
"MsgId": 1234567890123456
}
# Parameters
Parameter | Description |
---|---|
ToUserName | Mini Program's original ID |
FromUserName | Sender's openid |
CreateTime | Creation time of the message (integral) |
MsgType | image |
PicUrl | Image link (generated by the system) |
MediaId | Media ID of the image message. Data can be fetched by calling the Get Temporary Media API. |
MsgId | Message ID (64-bit integer) |
# Mini Program Card Messages
The following data package is generated when the user sends Mini Program card messages in a customer service session:
# In XML format
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1482048670</CreateTime>
<MsgType><![CDATA[miniprogrampage]]></MsgType>
<MsgId>1234567890123456</MsgId>
<Title><![CDATA[Title]]></Title>
<AppId><![CDATA[AppId]]></AppId>
<PagePath><![CDATA[PagePath]]></PagePath>
<ThumbUrl><![CDATA[ThumbUrl]]></ThumbUrl>
<ThumbMediaId><![CDATA[ThumbMediaId]]></ThumbMediaId>
</xml>
# In JSON format
{
"ToUserName": "toUser",
"FromUserName": "fromUser",
"CreateTime": 1482048670,
"MsgType": "miniprogrampage",
"MsgId": 1234567890123456,
"Title":"title",
"AppId":"appid",
"PagePath":"path",
"ThumbUrl":"",
"ThumbMediaId":""
}
# Parameters
Parameter | Description |
---|---|
ToUserName | Mini Program's original ID |
FromUserName | Sender's openid |
CreateTime | Creation time of the message (integral) |
MsgType | miniprogrampage |
MsgId | Message ID (64-bit integer) |
Title | Title |
AppId | Mini Program's appid |
PagePath | Mini Program's page path |
ThumbUrl | Temporary CDN link of the cover image |
ThumbMediaId | Temporary media ID of the cover image |
# Event of Entering Session
The following data package is generated when the user enters a customer service session by tapping the "customer service session button" in the Mini Program:
# In XML format
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1482048670</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[user_enter_tempsession]]></Event>
<SessionFrom><![CDATA[sessionFrom]]></SessionFrom>
</xml>
# In JSON format
{
"ToUserName": "toUser",
"FromUserName": "fromUser",
"CreateTime": 1482048670,
"MsgType": "event",
"Event": "user_enter_tempsession",
"SessionFrom": "sessionFrom"
}
# Parameters
Parameter | Description |
---|---|
ToUserName | Mini Program's original ID |
FromUserName | Sender's openid |
CreateTime | Creation time of the event (integral) |
MsgType | event |
Event | Event type, user_enter_tempsession |
SessionFrom | The session-from property set by the developer in the customer service session button. |