在Heroku上部署whatsap网络机器人

zujrkrfu  于 2022-11-13  发布在  其他
关注(0)|答案(2)|浏览(145)

I'm creating a whatsapp bot using the node library whatsapp-web.js After I'm done with the script it looks something like (I just put a overview of the orignal script) -
index.js

const {Client, LocalAuth, MessageMedia } = require('whatsapp-web.js');
const qrcode = require('qrcode-terminal');

const client = new Client({
  puppeteer: {
    args: ['--no-sandbox', "--disable-setuid-sandbox"]
  },
  authStrategy: new LocalAuth()
});
  
client.on('qr', (qr) => {
  console.log('qr received: ', qr);
qrcode.generate(qr, {small:true});
});
  
client.on('ready', () => {
    console.log('READY');
});

client.on('message', async msg => {
  let type = msg.type;
  let chat = await msg.getChat();
  if(chat.isGroup) {
    //do something
  }else {
    //
    if(msg.body === "ping") {
      msg.reply("pong");
    }
  }
});

Everything is fine with the script and it works good on linux or ubuntu (I already added puppeteer build pack on that Heroku app). As I need to run that script continuously I decided to put that on a worker process.
Procfile
worker: node index.js But now the problem comes in role, how can I authenticate here? I decided to remove that line from index.js
qrcode.generate(qr,{small:true}); And insted I thought I will print all the logs on heroku-cli
heroku logs -a wweb-bot #my app named as wweb-bot and from there access the key generated as qr. After that I'll turn it into a qrcode and scan it. When I did all setup and try it I was getting a continuously generating logs of qr keys. It's nonstop, and keep generating keys after every 15-20 sec. What's the problem here? Is it because Heroku has a read only environment or anything else is missing? Please help me how can i do it

jucafojl

jucafojl1#

移除或注解此代码
//验证策略:新建本地身份验证()
它不会在heroku上工作,但由于代码是在服务器上,你不需要一次又一次地扫描,你只需要扫描你重新启动服务器
但是如果你正面临 puppet 师的错误,那么在heroku /your project/settings/scroll down to adduildpack添加这两个构建包

  1. https://github.com/jontewks/puppeteer-heroku-buildpack
  2. https://github.com/heroku/heroku-buildpack-google-chrome
    然后重新部署应用程序
hpcdzsge

hpcdzsge2#

编辑:现在,whatsap-web.js添加了一个新功能,名为RemoteAuthStatergy,只需贯穿整个过程即可。

相关问题