As I am new to botkit, I have created the bot locally as per the docs. But when it is trying to call an external API using axios, below error shows -
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'get' of undefined
Here is the code -
const { BotkitConversation } = require("botkit");
const { axios } = require("axios");
module.exports = function(controller) {
const convo = new BotkitConversation('convo', controller);
convo.before('default', async(convo, bot) => {
axios.get(...https url...) //error line
.then(function (response) {
convo.setVar('api-response', response);
})
.catch(function (error) {
console.log(error);
})
});
convo.ask('What is your name?', async(response, convo, bot) => {
console.log(`user name is ${ response }`);
}, 'name');
convo.addAction('msg');
convo.addMessage('Hi {{vars.name}}! Welcome to my Botkit', 'msg');
}
Can someone point out what is wrong on this code?