행위

"Python telegram"의 두 판 사이의 차이

DB CAFE

(채팅방 메시지)
 
(같은 사용자의 중간 판 5개는 보이지 않습니다)
1번째 줄: 1번째 줄:
 
https://vmpo.tistory.com/m/85
 
https://vmpo.tistory.com/m/85
 +
 +
== 텔레그램에서 봇 생성 ==
 +
 +
# botfather 검색
 +
# @BotFahter 로 되어있는 채팅방을 클릭
 +
# /start 입력
 +
# /newbot 입력
 +
# 봇 이름 입력 (xxxx_bot)
 +
# Done! Congratulations on your new bot 메시지가 나오면 정상적으로 생성이 완료된 것
 +
# 성공 메시지 중에서 토큰 값을 따로 저장해줍니다.
 +
# 생성한 봇 채팅방으로 입장
 +
 +
 +
== 파이썬 텔레그램 라이브러리 설치 ==
 +
 +
<source lang=python>
 +
pip install python-telegram-bot
 +
</source>
 +
 +
 +
=== 텔레그램 봇 테스트 ===
 +
* 본인의 챗ID를 확인  (최초로 받은 토큰번호는 진짜ID가 아님)
 +
<source lang=python>
 +
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'
 +
</source>
 +
 +
=== 채팅방 메시지 ===
 +
 +
<source lang=python>
 +
import telegram
 +
 +
telgm_token = '1538331966:AAHPXJ6rKatzxXu0DyEwJkB-m2RO0Gbp0ZQ'
 +
 +
bot = telegram.Bot(token = telgm_token)
 +
 +
#updates = bot.getUpdates()
 +
 +
bot.sendMessage(chat_id = '676149244', text="안녕하세요  채봇입니다.")
 +
</source>
 +
 
[[Category:python]]
 
[[Category:python]]

2021년 1월 12일 (화) 19:44 기준 최신판

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="안녕하세요  채봇입니다.")