首页 > 解决方案 > whatsapp 聊天机器人不在 Heroku 中运行

问题描述

我正在构建一个聊天机器人 whattsapp 并部署在 heroku 中。But I am 但我被困在那一点上

在此处输入图像描述

info:     You're up to date
info:     [session:browser] Initializing browser...
warn:     [session:browser] Chrome not found, using chromium
error:    [session:browser] Error no open browser
error:    [session:browser] Failed to launch the browser process!
[0523/163914.552659:FATAL:zygote_host_impl_linux.cc(117)] No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/master/docs/linux/suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live dangerously and need an immediate workaround, you can try using --no-sandbox.
#0 0x55853747db39 base::debug::CollectStackTrace()
#1 0x5585373f04c3 base::debug::StackTrace::StackTrace()
#2 0x558537400c80 logging::LogMessage::~LogMessage()
#3 0x558535e92f5e content::ZygoteHostImpl::Init()
#4 0x55853739acf8 content::ContentMainRunnerImpl::Initialize()
#5 0x558537398e0b content::RunContentProcess()
#6 0x558537398f5c content::ContentMain()
#7 0x5585373ea3d2 headless::(anonymous namespace)::RunContentMain()
#8 0x5585373ea0bc headless::HeadlessShellMain()
#9 0x5585349eba03 ChromeMain
#10 0x7f0f848460b3 __libc_start_main
#11 0x5585349eb82a _start

Received signal 6
#0 0x55853747db39 base::debug::CollectStackTrace()
#1 0x5585373f04c3 base::debug::StackTrace::StackTrace()
#2 0x55853747d6db base::debug::(anonymous namespace)::StackDumpSignalHandler()
#3 0x7f0f860063c0 (/usr/lib/x86_64-linux-gnu/libpthread-2.31.so+0x153bf)
#4 0x7f0f8486518b gsignal
#5 0x7f0f84844859 abort
#6 0x55853747c665 base::debug::BreakDebugger()
#7 0x5585374010f2 logging::LogMessage::~LogMessage()
#8 0x558535e92f5e content::ZygoteHostImpl::Init()
#9 0x55853739acf8 content::ContentMainRunnerImpl::Initialize()
#10 0x558537398e0b content::RunContentProcess()
#11 0x558537398f5c content::ContentMain()
#12 0x5585373ea3d2 headless::(anonymous namespace)::RunContentMain()
#13 0x5585373ea0bc headless::HeadlessShellMain()
#14 0x5585349eba03 ChromeMain
#15 0x7f0f848460b3 __libc_start_main
#16 0x5585349eb82a _start
  r8: 0000000000000000  r9: 00007ffd34ef4aa0 r10: 0000000000000008 r11: 0000000000000246
 r12: 00007ffd34ef5db0 r13: aaaaaaaaaaaaaaaa r14: 00007ffd34ef5dc0 r15: 00007ffd34ef5540
  di: 0000000000000002  si: 00007ffd34ef4aa0  bp: 00007ffd34ef4cf0  bx: 00007f0f834db240
  dx: 0000000000000000  ax: 0000000000000000  cx: 00007f0f8486518b  sp: 00007ffd34ef4aa0
  ip: 00007f0f8486518b efl: 0000000000000246 cgf: 0000000000000033 erf: 0000000000000000
 trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[end of stack trace]
Calling _exit(1). Core file will not be generated.


TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

Error: Failed to launch the browser process!
[0523/163914.552659:FATAL:zygote_host_impl_linux.cc(117)] No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/master/docs/linux/suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live dangerously and need an immediate workaround, you can try using --no-sandbox.
#0 0x55853747db39 base::debug::CollectStackTrace()
#1 0x5585373f04c3 base::debug::StackTrace::StackTrace()
#2 0x558537400c80 logging::LogMessage::~LogMessage()
#3 0x558535e92f5e content::ZygoteHostImpl::Init()
#4 0x55853739acf8 content::ContentMainRunnerImpl::Initialize()
#5 0x558537398e0b content::RunContentProcess()
#6 0x558537398f5c content::ContentMain()
#7 0x5585373ea3d2 headless::(anonymous namespace)::RunContentMain()
#8 0x5585373ea0bc headless::HeadlessShellMain()
#9 0x5585349eba03 ChromeMain
#10 0x7f0f848460b3 __libc_start_main
#11 0x5585349eb82a _start

Received signal 6
#0 0x55853747db39 base::debug::CollectStackTrace()
#1 0x5585373f04c3 base::debug::StackTrace::StackTrace()
#2 0x55853747d6db base::debug::(anonymous namespace)::StackDumpSignalHandler()
#3 0x7f0f860063c0 (/usr/lib/x86_64-linux-gnu/libpthread-2.31.so+0x153bf)
#4 0x7f0f8486518b gsignal
#5 0x7f0f84844859 abort
#6 0x55853747c665 base::debug::BreakDebugger()
#7 0x5585374010f2 logging::LogMessage::~LogMessage()
#8 0x558535e92f5e content::ZygoteHostImpl::Init()
#9 0x55853739acf8 content::ContentMainRunnerImpl::Initialize()
#10 0x558537398e0b content::RunContentProcess()
#11 0x558537398f5c content::ContentMain()
#12 0x5585373ea3d2 headless::(anonymous namespace)::RunContentMain()
#13 0x5585373ea0bc headless::HeadlessShellMain()
#14 0x5585349eba03 ChromeMain
#15 0x7f0f848460b3 __libc_start_main
#16 0x5585349eb82a _start
  r8: 0000000000000000  r9: 00007ffd34ef4aa0 r10: 0000000000000008 r11: 0000000000000246
 r12: 00007ffd34ef5db0 r13: aaaaaaaaaaaaaaaa r14: 00007ffd34ef5dc0 r15: 00007ffd34ef5540
  di: 0000000000000002  si: 00007ffd34ef4aa0  bp: 00007ffd34ef4cf0  bx: 00007f0f834db240
  dx: 0000000000000000  ax: 0000000000000000  cx: 00007f0f8486518b  sp: 00007ffd34ef4aa0
  ip: 00007f0f8486518b efl: 0000000000000246 cgf: 0000000000000033 erf: 0000000000000000
 trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[end of stack trace]
Calling _exit(1). Core file will not be generated.


TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

    at onClose (/app/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:193:20)
    at Interface.<anonymous> (/app/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:183:68)
    at Interface.emit (events.js:388:22)
    at Interface.close (readline.js:429:8)
    at Socket.onend (readline.js:202:10)
    at Socket.emit (events.js:388:22)
    at endReadableNT (internal/streams/readable.js:1336:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)

robo.js

const wppconnect = require('@wppconnect-team/wppconnect');
const puppeteer = require('puppeteer');

puppeteer.launch({ args: ['--no-sandbox', '--disable--gpu', '--disable-setuid-sandbox'] });

(async () => {

    try {
        const cliente = await wppconnect.create((cliente) => {
            return cliente

        })
        start(cliente);
    } catch (err) {
        console.log(err)
    }

})()

const start = async (client) => {

    try {
        //usuário manda mensagem
        await client.onMessage(async (message) => {
            console.log('Mensagem digitada pelo usuário: ' + message.body);
            console.log("Body " + message)
            //stages(client,message)
            //const result = await client.sendText(message.from, 'PING! Mande um PONG para mim:')

        });
    } catch (err) {
        console.error('Error ', erro)
    }
}

包.json

{
  "name": "robo",
  "version": "1.0.0",
  "description": "",
  "main": "robo.js",
  "scripts": {
    "test": "nodemon robo.js",
    "start": "node robo.js "
  },
  "dependencies": {
    "@wppconnect-team/wppconnect": "^1.5.1",
    "puppeteer": "^5.5.0"
  }
}

我已经按照这些步骤操作了,但我仍然有错误

在 Heroku 上运行 Puppeteer 在 Heroku 上运行 Puppeteer 需要一些额外的依赖项,这些依赖项不包含在 Heroku 为您启动的 Linux 机器上。要添加部署依赖项,请将 Puppeteer Heroku buildpack 添加到 Settings > Buildpacks 下的应用程序的 buildpacks 列表中。

buildpack 的 url 是 https://github.com/jontewks/puppeteer-heroku-buildpack

确保在启动 Puppeteer 时使用“--no-sandbox”模式。这可以通过将其作为参数传递给您的 .launch() 调用来完成:puppeteer.launch({ args: ['--no-sandbox'] });。

当您单击添加 buildpack 时,只需将该 url 粘贴到输入中,然后单击保存。在下一次部署时,您的应用程序还将安装 Puppeteer 需要运行的依赖项。

如果您需要渲染中文、日文或韩文字符,您可能需要使用带有其他字体文件的 buildpack,例如 https://github.com/CoffeeAndCode/puppeteer-heroku-buildpack

@timleland 还有另一个简单的指南,其中包括一个示例项目:https ://timleland.com/headless-chrome-on-heroku/ 。

https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-on-heroku

标签: node.jsherokuchatbotwhatsapp

解决方案


这是答案:我必须创建整个教程才能使其正常工作:

https://medium.com/como-programar-em-1-dia/como-fazer-um-rob%C3%B4-de-whatsapp-chatbot-em-1-dia-644ee98054d7


推荐阅读