M
M
Maxim2022-03-06 14:22:25
JavaScript
Maxim, 2022-03-06 14:22:25

Node js how to make a valid axios request?

Hello everyone, I am writing a telegram bot on Node js using the node-telegram-bot-api

package In the handler I try to make a request using the axios \n package,
I get the following error:
622498dd7432c820692545.png

I make a request on line 34

const TelegramBot = require('node-telegram-bot-api')
const axios = require('axios').default
const fs = require('fs')
const token = '0000000000000000000000000000000000000000'

const { mainMenu, backMenu } = require('./navigations');


const bot = new TelegramBot(token, { polling: true });


bot.on('message', msg => {
    const chatID = msg.chat.id
    const text = msg.text

    switch (text) {
        case '/start':
            new Promise((resolve, reject) => {
                const welcomeImage = fs.readFileSync('./static/welcome.png')
                resolve(bot.sendPhoto(chatID, welcomeImage))
            }).then(() => {
                bot.sendMessage(chatID, 'Добро пожаловать в оптово-розничный магазин цветов в Оренбурге.', mainMenu)
            })

    }
})

bot.on('callback_query', msg => {
    const chatID = msg.message.chat.id
    const data = msg.data

    switch (data) {
        case 'catalog':
            axios.get('http://localhost:8000/telegram/categories')
                .then(data => {
                    console.log(data.data)
                })
                .catch(error => console.log(error))
            break
        case 'contacts':
            new Promise((resolve, reject) => {
                resolve(bot.sendLocation(chatID, 51.7826822, 55.1025064))
            }).then(() => {
                bot.sendMessage(chatID, `Телефон - Telegram - Whatsapp: \n+79120000000\n\nУл.Терешковой 000`, backMenu)
            })
            break
        case 'back':
            bot.sendMessage(chatID, '................................................................', mainMenu)
            break
    }
})


Has anyone encountered such a problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question