找不到bot帐户令牌密钥,viber bot, node.js



我对node.js和stackoverflow有点陌生,但我在创建viber bot时遇到了一些麻烦。使用这个https://chatbotslife.com/build-viber-bot-with-nodejs-a21487e5b65,创建了viber API,但找不到我在代码中放置API的位置。

const ViberBot = require('viber-bot').Bot,
BotEvents = require('viber-bot').Events,
TextMessage = require('viber-bot').Message.Text,
express = require('express');
const app = express();
if (!process.env.BOT_ACCOUNT_TOKEN) {
console.log('Could not find bot account token key.');
return;
}
if (!process.env.EXPOSE_URL) {
console.log('Could not find exposing url');
return;
}
const bot = new ViberBot({
authToken: process.env.BOT_ACCOUNT_TOKEN,
name: "Quest Bot",
avatar: "https://upload.wikimedia.org/wikipedia/commons/9/93/BirthdayQuest.jpg"
});
bot.on(BotEvents.SUBSCRIBED, response => {
response.send(new TextMessage(`Hi there ${response.userProfile.name}. I am ${bot.name}! Feel free to ask me anything.`));
});
bot.on(BotEvents.MESSAGE_RECEIVED, (message, response) => {
response.send(new TextMessage(`Message received.`));
});
const port = process.env.PORT || 3000;
app.use("/viber/webhook", bot.middleware());
app.listen(port, () => {
console.log(`Application running on port: ${port}`);
bot.setWebhook(`${process.env.EXPOSE_URL}/viber/webhook`).catch(error => {
console.log('Can not set webhook on following server. Is it running?');
console.error(error);
process.exit(1);
});
});

尝试先用单引号'包括你的API密钥'创建一个变量

const bot_account = 'API KEY'

然后初始化你的bot

const bot = new ViberBot({
authToken: bot_account,
name: "Quest Bot",
avatar: "https://upload.wikimedia.org/wikipedia/commons/9/93/BirthdayQuest.jpg"
});

如果您的系统设置了PATH变量,则可以通过process.env.PATH访问该变量,您可以使用该变量检查二进制文件的位置,并在需要时对外部调用它们。源

在您的情况下,没有路径,所以尝试通过变量分配。

相关内容

  • 没有找到相关文章

最新更新