小程序客服自动回复如何回复图片?

小程序 文章 2020-08-20 17:01 574 0 全屏看文

AI助手支持GPT4.0

小程序客服自动回复如何回复图片?How does the mini program customer service auto reply reply to the picture?

小程序客服自动回复如何回复图片?

小程序客服自动回复如何回复图片?

How to reply the picture automatically?

回答:

姑苏洛言:

1、新建云端的函数,设置config.json定义权限,如下config.json

{  "permissions": {    "openapi": [      "customerServiceMessage.send",      "customerServiceMessage.uploadTempMedia",      "customerServiceMessage.setTyping"    ]  }}

2、写云函数端代码,如下

if (event.Title == "我要进用户群"||event.Title =="关注公众号"||event) {    //设置输入状态    cloud.openapi.customerServiceMessage.setTyping({      touser: OPENID,      command: 'Typing'    })    //从云储存中拉取图片数据    const qunimg = await cloud.downloadFile({      fileID: "cloud://pm-hsfip.706d-pm-hsfip-1259751853/img/qun.png",    })    //上传图片素材到媒体库,并获取到图片id    const qunmedia = await cloud.openapi.customerServiceMessage.uploadTempMedia({      type: 'image',      media: {        contentType: 'image/png',        value: qunimg.fileContent      }    })    //向用户发送群二维码    await cloud.openapi.customerServiceMessage.send({      touser: OPENID,      msgtype: 'image',      image: {        mediaId: qunmedia.mediaId,      }    })    //取消状态设置    cloud.openapi.customerServiceMessage.setTyping({      touser: OPENID,      command: 'CancelTyping'    })  }

3、设置消息推送,路径如下 云开发-设置-全局设置-云函数接收消息推送 中添加消息类型为miniprogrampage,绑定云函数为新建的云函数。

https://developers.weixin.qq.com/community/develop/article/doc/000284ddf20298edd16ab6af25b813

青寒:我再给他发个非云端的说明。
青寒:

服务器开发时(非云端),

1,先使用https https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE 接口上传临时素材图片。

type值设为Image;

media值是图片文件绝对路径;

2,使用https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN 接口发送图片消息给用户

msgtype值是image;

image值是{"media_id":"MEDIA_ID"};

其中MEDIA_ID是第1个接口返回的临时素材media_id;

参见:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/customer-message/customerServiceMessage.send.html#method-http

A.G.A.I.N:这个可以帮到你

-EOF-

AI助手支持GPT4.0