Node.js 如何从电报机器人向MySql添加用户_数据?
代码: 我的数据库: 我想将此信息添加到数据库中,然后我应该将此数据库连接到我的站点。 我需要从电报中得到有关用户的信息Node.js 如何从电报机器人向MySql添加用户_数据?,node.js,telegram-bot,Node.js,Telegram Bot,代码: 我的数据库: 我想将此信息添加到数据库中,然后我应该将此数据库连接到我的站点。 我需要从电报中得到有关用户的信息 require('dotenv').config(); const TelegramBot = require('node-telegram-bot-api'); const bot = new TelegramBot(process.env.API_TOKEN, {polling: true}) const mysql = require('mysql'); const
require('dotenv').config();
const TelegramBot = require('node-telegram-bot-api');
const bot = new TelegramBot(process.env.API_TOKEN, {polling: true})
const mysql = require('mysql');
const con = mysql.createConnection({
host: '127.0.0.1',
user: 'root',
password: 'root',
database: 'elections'
});
bot.onText(/\/start /, msg => {
const chatId = msg.chat.id;
const user_id = msg.from.id;
const first_name = msg.from.first_name;
const last_name = msg.from.last_name;
const username = msg.from.user_name;
user_data = [chatId, first_name, last_name, username];
con.connect(function (err) {
if (err) throw err;
user_data = [user_id, first_name, last_name, username];
console.log("Connect succes!");
console.log(result);
bot.sendMessage(chatId, "Bot are working!");
con.query("INSERT INTO users (user_id, first_name, last_name, username) VALUES ?", [user_data], function (err, result){
if (err) throw err;
console.log("Result" + result);
})
})
})