whatsapp 聊天机器人不在 Heroku 中运行

Posted

技术标签:

【中文标题】whatsapp 聊天机器人不在 Heroku 中运行【英文标题】:whatsapp chatbot don't run in heroku 【发布时间】:2021-08-12 04:46:11 【问题描述】:

我正在构建一个聊天机器人 whattsapp 并部署在 heroku 中。但我是,但我被困在这一点上

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)
    

package.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 需要一些 Linux 盒子中未包含的其他依赖项 Heroku 为您旋转。要添加部署依赖项,请添加 Puppeteer Heroku buildpack 到您的应用程序的 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

【问题讨论】:

【参考方案1】:

这是答案:我必须创建整个教程才能让它发挥作用:

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

【讨论】:

以上是关于whatsapp 聊天机器人不在 Heroku 中运行的主要内容,如果未能解决你的问题,请参考以下文章

discord.js 机器人在本地工作,但不在 Heroku 上

不在 View Hierarchy 中时重新加载 UITableView/(一般是控制器)

从 WinForm C# 在 WhatsApp 桌面聊天中添加文件

部署后如何在 Heroku 中维护不在 git repo 中的文件

Laravel 5 android 聊天与推送通知,如 Whatsapp

如何在聊天中回复特定消息,就像使用 html css javascript/jquery 的 skype/whatsapp