행위

Python telegram

DB CAFE

thumb_up 추천메뉴 바로가기


https://vmpo.tistory.com/m/85

1 텔레그램에서 봇 생성[편집]

  1. botfather 검색
  2. @BotFahter 로 되어있는 채팅방을 클릭
  3. /start 입력
  4. /newbot 입력
  5. 봇 이름 입력 (xxxx_bot)
  6. Done! Congratulations on your new bot 메시지가 나오면 정상적으로 생성이 완료된 것
  7. 성공 메시지 중에서 토큰 값을 따로 저장해줍니다.
  8. 생성한 봇 채팅방으로 입장


2 파이썬 텔레그램 라이브러리 설치[편집]

pip install python-telegram-bot


2.1 텔레그램 봇 테스트[편집]

  • 본인의 챗ID를 확인 (최초로 받은 토큰번호는 진짜ID가 아님)
import telegram

telgm_token = '1538331966:AAHPXJ6rKatzxXu0DyEwJkB-m2RO0Gbp0ZQ'

bot = telegram.Bot(token = telgm_token)

updates = bot.getUpdates()

print(updates)

for i in updates:
    print(i)

print('start telegram chat bot')

# 본인의 챗ID를 확인 
#'676149244'

2.2 채팅방 메시지[편집]

import telegram

telgm_token = '1538331966:AAHPXJ6rKatzxXu0DyEwJkB-m2RO0Gbp0ZQ'

bot = telegram.Bot(token = telgm_token)

#updates = bot.getUpdates()

bot.sendMessage(chat_id = '676149244', text="안녕하세요  채봇입니다.")