Receiving Messages and Events

View Markdown

Last edited on 2026-07-23

You can use <button open-type="contact" /> in a page to display the customer service session button.

When a user sends a message in a customer service session or triggers an event through specific user actions, the WeChat server sends the message or event data packet to the URL, Cloud Development Cloud Function, or Cloud Hosting Service configured by the developer (see Message Push for details). After receiving the request, the developer can use the Send Customer Service Message API to reply asynchronously.

The pushed JSON and XML data packet structures for each message type are as follows.

Text Message

When a user sends a text message in a customer service session, the following data packet is generated:

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>

JSON Format

{
  "ToUserName": "toUser",
  "FromUserName": "fromUser",
  "CreateTime": 1482048670,
  "MsgType": "text",
  "Content": "this is a test",
  "MsgId": 1234567890123456
}

Parameter Description

Parameter Description
ToUserName Original ID of Mini Program
FromUserName OpenID of the sender
CreateTime Message creation time (integer)
MsgType text
Content Text message content
MsgId Message ID, 64-bit integer

Image Message

When a user sends an image message in a customer service session, the following data packet is generated:

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>

JSON Format

{
  "ToUserName": "toUser",
  "FromUserName": "fromUser",
  "CreateTime": 1482048670,
  "MsgType": "image",
  "PicUrl": "this is a url",
  "MediaId": "media_id",
  "MsgId": 1234567890123456
}

Parameter Description

Parameter Description
ToUserName Original ID of Mini Program
FromUserName OpenID of the sender
CreateTime Message creation time (integer)
MsgType image
PicUrl Image URL (generated by the system)
MediaId Media ID of the image message. You can call the get temporary material API to retrieve the data.
MsgId Message ID, 64-bit integer

Mini Program Card Message

When a user sends a Mini Program card message in a customer service session, the following data packet is generated:

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>

JSON Format

{
  "ToUserName": "toUser",
  "FromUserName": "fromUser",
  "CreateTime": 1482048670,
  "MsgType": "miniprogrampage",
  "MsgId": 1234567890123456,
  "Title":"title",
  "AppId":"appid",
  "PagePath":"path",
  "ThumbUrl":"",
  "ThumbMediaId":""
}

Parameter Description

Parameter Description
ToUserName Original ID of Mini Program
FromUserName OpenID of the sender
CreateTime Message creation time (integer)
MsgType miniprogrampage
MsgId Message ID, 64-bit integer
Title Title
AppId AppID of Mini Program
PagePath Page path of Mini Program
ThumbUrl Temporary CDN link of the cover image
ThumbMediaId Temporary media ID of the cover image

Enter Conversation Event

When a user enters a customer service session via the Mini Program "Customer Service Conversation Button," the following data packet is generated:

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>

JSON Format

{
  "ToUserName": "toUser",
  "FromUserName": "fromUser",
  "CreateTime": 1482048670,
  "MsgType": "event",
  "Event": "user_enter_tempsession",
  "SessionFrom": "sessionFrom"
}

Parameter Description

Parameter Description
ToUserName Original ID of Mini Program
FromUserName Sender's OpenID
CreateTime Event creation time (integer)
MsgType event
Event Event type, user_enter_tempsession
SessionFrom session-from attribute set by the developer in Customer Service Session Button