# Post a customer service message
If Weixin Mini Program sets the message push, the ordinary WeChat user sends a message to the Mini Program customer service, the WeChat server will first post the message to the developer'sOn URL, if you want to forward a message to the web-based customer service tool, you need the developer to return a message with the MsgType of transfer_customer_service in the response package, and the WeChat server will forward the message sent to the customer service system after receiving the response.
After the user is accessed by the customer service, and before the customer service closes the session, messages sent by the user are forwarded directly to the customer service system while the session is in progress.When the customer service is not closed for more than 30 minutes, the WeChat server automatically stops forwarding to the customer service and sends the message back to the developer's completed URL.
When the user is in the waiting queue, the message sent by the user will still be pushed to the URL filled in by the developer.
Particular note here is that only messages sent by WeChat users should be forwarded, and other events (such as when a user calls a customer service session from Weixin Mini Program) should not be forwarded; otherwise the customer service will see some meaningless messages on the customer service system.
# Re forward messages to the web-based customer service tool
As long as the developer returns the MsgType message transfer_customer_service in the response package, the WeChat server receives the response and forwards the message to the customer service system.
If you are using your own server to receive a message push, you need to return XML data in the following format:
<xml>
<ToUserName><![CDATA[touser]]></ToUserName>
<FromUserName><![CDATA[fromuser]]></FromUserName>
<CreateTime>1399197672</CreateTime>
<MsgType><![CDATA[transfer_customer_service]]></MsgType>
</xml>
Parameter explaination
| parameter | Do I have to? | describe |
|---|---|---|
| ToUserName | yes | Recipient account number (OpenID received) |
| FromUserName | yes | Weixin Mini Program Original id |
| CreateTime | yes | Message Creation Time (integer) |
| MsgType | yes | transfer_customer_service |
If you use the message received by the cloud function to push , you need to returnJSONdata in the same format after the cloud function is triggered by a customer service message:
// ...
exports.main = async (event, context) => {
// 判断处理客服消息 ...
// 最后返回 JSON
return {
MsgType: 'transfer_customer_service',
ToUserName: 'touser',
FromUserName: 'fromuser',
CreateTime: parseInt(+new Date / 1000),
}
}