# telegram botfather
텔레그램을 깔고 botfather을 검색한다.
그 후, /newbot 명령어를 채팅치면 봇이름과 사용자이름을 지을수 있다.
마지막으로 토큰값을 받는데, 이 토큰값이 있어야 봇에대해 코딩이 가능하다.
# node환경에서 사용.
먼저 npm i node-telegram-bot-api명령으로 모듈을 깔아준다.
그다음 아래 코드를 복붙하샘.
const TelegramBot = require("node-telegram-bot-api");
const token = "토큰값";
const bot = new TelegramBot(token, { polling: true });
bot.on("message", (msg) => {
const chatId = msg.chat.id;
console.log(msg);
bot.sendMessage(chatId, "안녕");
});
# bot.sendMessage메서드를 자주 쓰자.
bot.on메서드에서 chatId를 콘솔로찍어보면 내 채팅방 아이디 나온다.
'etc > devTools' 카테고리의 다른 글
notion api / start & create page (0) | 2024.09.08 |
---|---|
postman / api test tool (0) | 2024.09.08 |
vs코드 에디터와 터미널 focus 변경 단축키 만들기 (0) | 2024.09.08 |
moba x term 아래로 생겨버리는 창 없애기 (0) | 2023.11.26 |
텔레그램 메세지보내기 봇만들기 (0) | 2022.09.02 |