Viber setWebhook завершился ошибкой - аргумент "данные" должен быть одним из типов: строка, TypedArray или DataView. Полученный объект типа
Пытаюсь настроить viber webhook. У меня уже есть экспресс-настройка сервера. Поэтому я просто добавляю бота как промежуточное ПО. Все найдено, и сервер запущен.
Однажды позвонил bot.setWebhook(process.env.VB_WEBHOOK_URL)
, он выдает ошибку: -> The "data" argument must be one of type string, TypedArray, or DataView. Received type object
Он отлично работает при попытке с ngrok
в конфигурации локального сервера. Единственная проблема при настройке веб-перехватчика в конфигурации живого сервера. Пожалуйста, проверьте код ниже
const path = require("path");
const publicPath = path.join(__dirname, "../public");
const express = require("express");
const http = require("http");
const env = require("dotenv");
const bodyParser = require("body-parser");
env.config({
path: path.resolve(__dirname + "/.env")
});
const app = express();
const server = http.createServer(app);
const adminActionRoute = require('./routes/admin');
app.use(express.static(publicPath));
app.use(bodyParser.json({ verify: verifyRequestSignature }));
app.use(bodyParser.urlencoded({ limit: '200mb', extended: true }));
app.use('/api/admin', adminActionRoute);
const viberBot = require('../viber_chat/utils/bot')
app.use('/viber/webhook', viberBot.middleware())
server.listen(5000, () => {
viberBot.setWebhook(process.env.VB_WEBHOOK_URL);
console.log("server starts at port 5000");
});
module.exports = server; //for testing
Файл '/viber_chat/utils/bot'
require('dotenv').config();
const ViberBot = require('viber-bot').Bot;
const BotEvents = require('viber-bot').Events;
const logger = require('../utils/logger');
const bot = new ViberBot(logger, {
authToken: process.env.VB_API_KEY,
name: "Bot Name",
avatar: ""
});
bot.onSubscribe(response => {
});
bot.on(BotEvents.CONVERSATION_STARTED, (response) => {
})
module.exports = bot;
TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be one of type string, TypedArray, or DataView. Received type object
at Hmac.update (internal/crypto/hash.js:58:11)
at MessageValidator._calculateHmacFromMessage (/home/thettun/project_folder/funfun_viber/node_modules/viber-bot/lib/message/message-validator.js:19:54)
at MessageValidator.validateMessage (/home/thettun/project_folder/funfun_viber/node_modules/viber-bot/lib/message/message-validator.js:11:30)
at _app.use (/home/thettun/project_folder/funfun_viber/node_modules/viber-bot/lib/middleware.js:61:32)
at Layer.handle [as handle_request] (/home/thettun/project_folder/funfun_viber/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/thettun/project_folder/funfun_viber/node_modules/express/lib/router/index.js:317:13)
at /home/thettun/project_folder/funfun_viber/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/home/thettun/project_folder/funfun_viber/node_modules/express/lib/router/index.js:335:12)
at next (/home/thettun/project_folder/funfun_viber/node_modules/express/lib/router/index.js:275:10)
at textParser (/home/thettun/project_folder/funfun_viber/node_modules/body-parser/lib/types/text.js:60:7)
at Layer.handle [as handle_request] (/home/thettun/project_folder/funfun_viber/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/thettun/project_folder/funfun_viber/node_modules/express/lib/router/index.js:317:13)
at /home/thettun/project_folder/funfun_viber/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/home/thettun/project_folder/funfun_viber/node_modules/express/lib/router/index.js:335:12)
at next (/home/thettun/project_folder/funfun_viber/node_modules/express/lib/router/index.js:275:10)
at expressInit (/home/thettun/project_folder/funfun_viber/node_modules/express/lib/middleware/init.js:40:5)
1 ответ
Эта тема решила это для меня
т.е. не используйте bodyParser при вызове setWebhook, только на определенных маршрутах:
// app.use(bodyParser.json());