在项目根目录下新建消息推送配置文件 temp-cloud-callback-config.json
{
"enable": true,
"callbacks": [
{
"msgType": 1,
"functionName": "云函数名",
"env": "环境ID"
}
]
}
|
好了之后 右键 上传配置 __此功能已经废弃 2019-06-20 更 __吼吼》
2.云函数中处理消息
此时可调用客服消息发送接口回复消息,一个简单的接收到消息后统一回复 “收到” 的示例如下:
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
await cloud.openapi.customerServiceMessage.send({
touser: wxContext.OPENID,
msgtype: 'text',
text: {
content: '收到',
},
})
return 'success'
}
|
event结构如下:
{
"FromUserName": "ohl4L0Rnhq7vmmbT_DaNQa4ePaz0",
"ToUserName": "wx3d289323f5900f8e",
"Content": "测试",
"CreateTime": 1555684067,
"MsgId": "49d72d67b16d115e7935ac386f2f0fa41535298877_1555684067",
"MsgType": "text"
}
|
|
注意:用最新的开发者工具,还有基础库要2.7.0(忘记了要不要,哈哈)
详情请查看:https://www.cnblogs.com/chmo/p/10931531.html
我也有一点不明白的地方:
文档上有说进入会话这个事件,但是我在试验中,得不到响应