【问题标题】:Viber Chatbot - Creating an echo botViber Chatbot - 创建回声机器人
【发布时间】:2019-02-28 12:06:59
【问题描述】:

我正在关注 Viber Node.JS 机器人文档并正在创建一个回显机器人,它将向用户重复消息。但它不起作用,机器人不回复我的消息。代码如下:

'use strict';

const ViberBot = require('viber-bot').Bot;
const BotEvents = require('viber-bot').Events;

const bot = new ViberBot({
    authToken: "api-key",
    name: "Override API",
    avatar: "https://cdn3.iconfinder.com/data/icons/customer-support-7/32/40_robot_bot_customer_help_support_automatic_reply-512.png" // It is recommended to be 720x720, and no more than 100kb.
});

// Perfect! Now here's the key part:
bot.on(BotEvents.MESSAGE_RECEIVED, (message, response) => {
    // Echo's back the message to the client. Your bot logic should sit here.
    response.send(message);
});


// Wasn't that easy? Let's create HTTPS server and set the webhook:
const https = require('https');
const port = process.env.PORT || 8080;

// Viber will push messages sent to this URL. Web server should be internet-facing.
const webhookUrl = "https://webhook.site/09f0b45e-1ad8-466c-9441-e5edb3d783e3";

https.createServer(bot.middleware()).listen(port, () => bot.setWebhook(webhookUrl));

【问题讨论】:

  • 你使用http还是https服务器?我的意思是,你的代码在哪里运行?在您的计算机上还是在服务器上?
  • 它在我的电脑上运行
  • 你的 bot webhook url 是什么?

标签: node.js chatbot viber viber-api viber-bot


【解决方案1】:

试试这个:

const webhookUrl = "https://webhook.site/09f0b45e-1ad8-466c-9441-e5edb3d783e3";

app.use('/viber/webhook', bot.middleware());

app.listen(port, () => {
    console.log(`Application running on port: ${port}`);
    bot.setWebhook(`${webhookUrl}/viber/webhook`).catch(error => {
        console.log('Can not set webhook on following server. Is it running?');
        console.error(error);
        process.exit(1);
    });
});

代替:

https.createServer(bot.middleware()).listen(port, () => bot.setWebhook(webhookUrl));

Source

【讨论】:

    猜你喜欢
    • 2020-08-25
    • 1970-01-01
    • 2022-07-18
    • 2021-10-19
    • 2021-02-03
    • 1970-01-01
    • 2010-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多