WeChat mini program uses mini program customer service message cloud function to automatically reply

 First we put this button on the page

<button style="background-color: black;width: auto;" open-type="contact" </button>

 Then we create a new cloud function and upload it, my name is customerService

// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  
  await cloud.openapi.customerServiceMessage.send({
    touser: wxContext.OPENID,
    msgtype: 'text',
    text: {
      content: '欢迎来到摄影作品展示小程序!我是您的客服,非常高兴为您服务。如果您有任何关于摄影作品、展览或其他方面的问题,都可以随时向我咨询。如果您需要帮助或有任何疑问,请随意问我。您也可以通过扫描下方的二维码或者搜索微信号 a1803233552 添加我为好友,我将随时为您提供帮助和回答问题。期待与您互动,分享摄影的乐趣!祝您在我们的小程序中度过愉快的时光!',
    },
  })

  return 'success'
}

 Then we select Cloud Function in WeChat Developer Tools Point Cloud Development-Settings-Other Settings-Push Mode, and then click Add Message Push.

 Then select the cloud function we just uploaded. The message type here is text, which means it is triggered when the user sends a text message to customer service.

 Then click Enable, here I have enabled it so it is displayed as disabled.

 Then we came to the mini program to test and we can see that it can automatically reply.

Advertise your own mini program

Search Impressionist Portraits to visit

Guess you like

Origin blog.csdn.net/u014288878/article/details/132527254