first commit
This commit is contained in:
56
bot.js
Normal file
56
bot.js
Normal file
@@ -0,0 +1,56 @@
|
||||
const TelegramBot = require('node-telegram-bot-api');
|
||||
require('dotenv').config()
|
||||
|
||||
const axios = require('axios')
|
||||
|
||||
const tokenTg = process.env.TOKEN_TG;
|
||||
const tokenAi = process.env.TOKEN_AI;
|
||||
const accessId = process.env.SECRET_ID;
|
||||
|
||||
|
||||
const bot = new TelegramBot(tokenTg, { polling: true });
|
||||
|
||||
console.log('Бот запущен...');
|
||||
|
||||
|
||||
bot.onText(/\/info/, (msg)=>{
|
||||
const message = `Информация о боте: \n
|
||||
'/start' - перезапускает чат, забывает контекст прошлого диалого \n
|
||||
'/toggleModel' - Выбор модели (еще не доступен)`
|
||||
const chatId = msg.chat.id
|
||||
|
||||
bot.sendMessage(chatId, message)
|
||||
})
|
||||
|
||||
|
||||
bot.onText(/\/start/, (msg) => {
|
||||
const chatId = msg.chat.id;
|
||||
const chatType = msg.chat.type
|
||||
bot.sendMessage(chatId, `Чат перезапущен, тип чата ${chatType}`);
|
||||
});
|
||||
|
||||
|
||||
bot.on('message', (msg) => {
|
||||
const chatId = msg.chat.id;
|
||||
|
||||
const user = msg.from
|
||||
|
||||
if (msg.text && msg.text.startsWith('/')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.photo) {
|
||||
bot.sendMessage(chatId, 'Красиво, но такое мне не надо');
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.document) {
|
||||
bot.sendMessage(chatId, 'Такое мне не надо');
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.text) {
|
||||
bot.sendMessage(chatId, `Ты написал: ${msg.text}`);
|
||||
return;
|
||||
}
|
||||
});
|
||||
3
example.env
Normal file
3
example.env
Normal file
@@ -0,0 +1,3 @@
|
||||
TOKEN_TG =
|
||||
TOKEN_AI =
|
||||
SECRET_ID =
|
||||
17
package.json
Normal file
17
package.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "bot-ai",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"axios": "^1.13.2",
|
||||
"dotenv": "^17.2.3",
|
||||
"node-telegram-bot-api": "^0.67.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user