Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const TelegramBot = require('node-telegram-bot-api');
- // replace the value below with the Telegram token you receive from @BotFather
- const token = '398047618:AAFAWYC1a3lutjunglWL6IPcTMk1YXjxxxx';
- // Create a bot that uses 'polling' to fetch new updates
- const bot = new TelegramBot(token, {polling: true});
- // Matches "/echo [whatever]"
- bot.onText(/\/echo (.+)/, (msg, match) => {
- // 'msg' is the received Message from Telegram
- // 'match' is the result of executing the regexp above on the text content
- // of the message
- const chatId = msg.chat.id;
- const resp = match[1]; // the captured "whatever"
- // send back the matched "whatever" to the chat
- bot.sendMessage(chatId, resp);
- });
- var mysql = require('mysql');
- var con = mysql.createConnection({
- host: "localhost",
- user: "root",
- password: "",
- database: "node_js_chat_bot_telegram"
- });
- con.connect();
- var queryString = con.query("SELECT * FROM question WHERE name_question = 'shallom'");
- con.query(queryString, function(err, rows, fields) {
- if (err) throw err;
- for (var i in rows) {
- console.log('Post Titles: ', rows[i].name_question);
- }
- });
- // console.log(queryString);
- result = queryString;
- con.end();
- // result = queryString;
- chat_1 = "shallom";
- // Listen for any kind of message. There are different kinds of
- // messages.
- //
- bot.on('message', (msg) => {
- var hi = "hi";
- if (msg.text.toString().toLowerCase().indexOf(hi) === 0) {
- // bot.sendMessage(msg.chat.id,"Hello dear user");
- bot.sendMessage(msg.chat.id,"Hello dear " + msg.from.first_name);
- }
- var shallom = chat_1;
- if (msg.text.toString().toLowerCase().indexOf(shallom) === 0) {
- // bot.sendMessage(msg.chat.id,"Hello dear user");
- bot.sendMessage(msg.chat.id,"Shallom " + msg.from.first_name);
- }
- var Var_Chat = chat_1;
- if (msg.text.toString().toLowerCase().indexOf(Var_Chat) === 0) {
- // bot.sendMessage(msg.chat.id,"Hello dear user");
- bot.sendMessage(msg.chat.id,result + msg.from.first_name);
- }
- //
- // var Var_Chat2 = con.query("SELECT * FROM question WHERE name_question = 'how are you'");
- // // var Var_Chat2 = 'SELECT * FROM question WHERE name_question = 'chat_1;
- // if (msg.text.toString().toLowerCase().indexOf(Var_Chat2) === 0) {
- // // con.query(queryString, function(err, rows, fields) {
- // // if (err) throw err;
- // // for (var i in rows) {
- // // console.log('Post Titles: ', rows[i].name_question);
- // // }
- // // });
- // bot.sendMessage(msg.chat.id,result + msg.from.first_name);
- // }
- var bye = "bye";
- if (msg.text.toString().toLowerCase().includes(bye)) {
- // bot.sendMessage(msg.chat.id, "Hope to see you around again , Bye");
- bot.sendMessage(msg.chat.id, "Have a nice day " + msg.from.first_name);
- }
- var location = "location";
- if (msg.text.indexOf(location) === 0) {
- bot.sendLocation(msg.chat.id,44.97108, -104.27719);
- bot.sendMessage(msg.chat.id, "Here is the point");
- }
- var what = "idiot";
- if (msg.text.includes(what)) {
- bot.kickChatMember(msg.chat.id, msg.from.id);
- }
- });
Add Comment
Please, Sign In to add comment