# Receive messages and events

Use in the page <button open-type="contact" /> The Enter Customer Service Session button can be displayed.

When a user sends a message in a customer service session, or an event is pushed by some specific user action, the WeChat server sends a message or event packet to the developer's URL / Cloud development cloud function / [Cloud Hosting Services](https://developers.weixin.qq.com/miniprogram/dev/wxcloudrun /src/Guide/Weixin/push.html)(Please refer toMessage Push)。Upon receipt of the request, the developer can use the Send Customer Service Message Interface for asynchronous replies.

The structure of the push JSON and XML digital packet for each message type is as follows.

# Text message

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

# XML format

<xml>
   <ToUser ><![CDATA[ToUser]]></ToUser >
   <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
}

# Dxplaination of parameters

parameter Introductions
ToUser The original ID of the Mini Program
FromUserName Sender's openid
CreateTime Message Creation Time(Integers)
MsgType text
Content Text message content
MsgId Message id, 64-bit integer

# Photo Message

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

# XML format

<xml>
      <ToUser ><![CDATA[ToUser]]></ToUser >
      <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
}

# Dxplaination of parameters

parameter Introductions
ToUser The original ID of the Mini Program
FromUserName Sender's openid
CreateTime Message Creation Time(Integers)
MsgType image
PicUrl Image link (generated by the system)
MediaId Picture message media id, which can be called[Get Temporary Material]((getTempMedia)Interface to pull 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 packets are generated:

# XML format

<xml>
  <ToUser ><![CDATA[ToUser]]></ToUser >
  <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":""
}

# Dxplaination of parameters

parameter Introductions
ToUser The original ID of the Mini Program
FromUserName Sender's openid
CreateTime Message Creation Time(Integers)
MsgType miniprogrampage
MsgId Message id, 64-bit integer
Title title
AppId Mini Program appid
PagePath Mini Program page path
ThumbUrl Temporary cdn link for cover image
ThumbMediaId Temporary material id for cover image

# Enter Session Event

When the user enters the customer service session in the Mini Program "Customer Service Session Button," the following data packets will be generated:

# XML format

<xml>
    <ToUser ><![CDATA[ToUser]]></ToUser >
    <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"
}

# Dxplaination of parameters

parameter Introductions
ToUser The original ID of the Mini Program
FromUserName Sender's openid
CreateTime Event Creation Time(Integers)
MsgType event
Event Event type, user_Enter_tempsession
SessionFrom The developer is inCustomer Service Session ButtonSet of session-from attribute