从Viber bot向botbuilder-viber

时间:2018-05-21 10:38:42

标签: node.js express botframework bots viber

npm-module中的问题

https://www.npmjs.com/package/botbuilder-viber

平台

操作系统:Ubuntu

节点版本:9.3.0

NPM版本:5.5.1。

代码

var viber = require('botbuilder-viber');
var express = require('express');
var bodyParser = require('body-parser');

var viberOptions = {
  Token: '***',
  Name: '***',
  AvatarUrl: '***'
}
var viberChannel = new viber.ViberEnabledConnector(viberOptions);

var expressApp = express();

expressApp.listen(process.env.port || process.env.PORT || 3978, function() {
    console.log("Express server is running.");
});

expressApp.use(bodyParser.urlencoded({ extended: false }));

expressApp.use(bodyParser.json());

bot.connector(viber.ViberChannelId, viberChannel);

expressApp.use('/viber/webhook', viberChannel.listen());

预期行为

没有错误

实际行为

从我的viber bot发送消息时出现错误(每次重复两次)。

TypeError [ERR_INVALID_ARG_TYPE]:"数据"参数必须是string,TypedArray或DataView类型之一 在Hmac.update(内部/ crypto / hash.js:53:11) 在MessageValidator._calculateHmacFromMessage(/app/node_modules/viber-bot/lib/message/message-validator.js:17:54) 在MessageValidator.validateMessage(/app/node_modules/viber-bot/lib/message/message-validator.js:11:30) at _app.use(/app/node_modules/viber-bot/lib/middleware.js:61:32) 在Layer.handle [as handle_request](/app/node_modules/express/lib/router/layer.js:95:5) 在trim_prefix(/app/node_modules/express/lib/router/index.js:317:13) at /app/node_modules/express/lib/router/index.js:284:7 在Function.process_params(/app/node_modules/express/lib/router/index.js:335:12) 在下一个(/app/node_modules/express/lib/router/index.js:275:10) 在textParser(/app/node_modules/body-parser/lib/types/text.js:60:7) 在Layer.handle [as handle_request](/app/node_modules/express/lib/router/layer.js:95:5) 在trim_prefix(/app/node_modules/express/lib/router/index.js:317:13) at /app/node_modules/express/lib/router/index.js:284:7 在Function.process_params(/app/node_modules/express/lib/router/index.js:335:12) 在下一个(/app/node_modules/express/lib/router/index.js:275:10) at expressInit(/app/node_modules/express/lib/middleware/init.js:40:5) 在Layer.handle [as handle_request](/app/node_modules/express/lib/router/layer.js:95:5) 在trim_prefix(/app/node_modules/express/lib/router/index.js:317:13) at /app/node_modules/express/lib/router/index.js:284:7 在Function.process_params(/app/node_modules/express/lib/router/index.js:335:12) 在下一个(/app/node_modules/express/lib/router/index.js:275:10) 在查询(/app/node_modules/express/lib/middleware/query.js:45:5) 在Layer.handle [as handle_request](/app/node_modules/express/lib/router/layer.js:95:5) 在trim_prefix(/app/node_modules/express/lib/router/index.js:317:13) at /app/node_modules/express/lib/router/index.js:284:7 在Function.process_params(/app/node_modules/express/lib/router/index.js:335:12) 在下一个(/app/node_modules/express/lib/router/index.js:275:10) 在Function.handle(/app/node_modules/express/lib/router/index.js:174:3)

TypeError [ERR_INVALID_ARG_TYPE]:"数据"参数必须是string,TypedArray或DataView类型之一 在Hmac.update(内部/ crypto / hash.js:53:11) 在MessageValidator._calculateHmacFromMessage(/app/node_modules/viber-bot/lib/message/message-validator.js:17:54) 在MessageValidator.validateMessage(/app/node_modules/viber-bot/lib/message/message-validator.js:11:30) at _app.use(/app/node_modules/viber-bot/lib/middleware.js:61:32) 在Layer.handle [as handle_request](/app/node_modules/express/lib/router/layer.js:95:5) 在trim_prefix(/app/node_modules/express/lib/router/index.js:317:13) at /app/node_modules/express/lib/router/index.js:284:7 在Function.process_params(/app/node_modules/express/lib/router/index.js:335:12) 在下一个(/app/node_modules/express/lib/router/index.js:275:10) 在textParser(/app/node_modules/body-parser/lib/types/text.js:60:7) 在Layer.handle [as handle_request](/app/node_modules/express/lib/router/layer.js:95:5) 在trim_prefix(/app/node_modules/express/lib/router/index.js:317:13) at /app/node_modules/express/lib/router/index.js:284:7 在Function.process_params(/app/node_modules/express/lib/router/index.js:335:12) 在下一个(/app/node_modules/express/lib/router/index.js:275:10) at expressInit(/app/node_modules/express/lib/middleware/init.js:40:5) 在Layer.handle [as handle_request](/app/node_modules/express/lib/router/layer.js:95:5) 在trim_prefix(/app/node_modules/express/lib/router/index.js:317:13) at /app/node_modules/express/lib/router/index.js:284:7 在Function.process_params(/app/node_modules/express/lib/router/index.js:335:12) 在下一个(/app/node_modules/express/lib/router/index.js:275:10) 在查询(/app/node_modules/express/lib/middleware/query.js:45:5) 在Layer.handle [as handle_request](/app/node_modules/express/lib/router/layer.js:95:5) 在trim_prefix(/app/node_modules/express/lib/router/index.js:317:13) at /app/node_modules/express/lib/router/index.js:284:7 在Function.process_params(/app/node_modules/express/lib/router/index.js:335:12) 在下一个(/app/node_modules/express/lib/router/index.js:275:10) 在Function.handle(/app/node_modules/express/lib/router/index.js:174:3)

1 个答案:

答案 0 :(得分:0)

在此连接器开始工作后,我只将bodyparser添加到特定路由。