一:安装
npm install node-telegram-bot-api
二:引入node-telegram-bot-api和fs模块,发送本地媒体文件时需要用到
const TelegramBot = require('node-telegram-bot-api');
const fs = require('fs')
三:在Tg的BotFather机器人那里创建你的机器人,获取机器人的token,接入代码
const botToken = "5575711741:AAFHdel52xxxxxxxxxxN1N80exxxxUOaRw"
const bot = new TelegramBot(botToken, { polling: true });
bot.on('message', async (msg) => {
//接受所有消息回调函数
//chatId = msg.chat.chatId
})
// 发送消息
//chatId : 聊天的id
// msg: 回复的消息
//option: { reply_to_message_id: msg.message_id, parse_mode: 'HTML',
// disable_web_page_preview: true } 要回复的消息id,格式化选项,是否禁用网页链接浏览
// 更多参数可以看官方文档
bot.sendMessage(chatId,msg,option) // 返回promise .then获取结果.c