๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ› ๏ธ ์ž๋™ํ™” ๋ฐ ์Šคํฌ๋ฆฝํŠธ/๐Ÿงฐ Python

Telegram API๋ฅผ ํ™œ์šฉํ•œ bot ๋งŒ๋“ค๊ธฐ

by Ji-Hoon 2022. 10. 19.

์ด๋ฒˆ์—๋Š” Telegram ์„ ํ™œ์šฉํ•˜์—ฌ ํŠน์ •ํ•œ ์กฐ๊ฑด์ผ ๋•Œ ์•Œ๋ฆผ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” bot ์„ ๋งŒ๋“ค์–ด ๋ณด๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.

 

์šฐ์„  Telegram ์—์„œ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ผ ๊ณ„์ •(bot)์„ ๋งŒ๋“ค์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค

1. Telegram API ์ค€๋น„ํ•˜๊ธฐ

1.1. PC ์— ํ…”๋ ˆ๊ทธ๋žจ ์„ค์น˜ ํ›„ ๊ฒ€์ƒ‰์ฐฝ์— "BotFather" ๋ฅผ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค. 

 

1.2 ์„ ํƒ ํ›„ “/start” ๋ฅผ ์ž…๋ ฅ ์ „์†ก ํ•ฉ๋‹ˆ๋‹ค.

 

2. ์ƒˆ๋กœ์šด Telegram Bot ์„ ๋งŒ๋“ค ์ฐจ๋ก€!

- “/newbot” ์ž…๋ ฅ ํ›„ ์›ํ•˜๋Š” bot์˜ ์ด๋ฆ„์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

- Bot์˜ ์ด๋ฆ„์—๋Š” ‘bot’์ด๋ผ๋Š” ๋‹จ์–ด๊ฐ€ ํฌํ•จ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

- ๋‘๋ฒˆ์งธ ๋นจ๊ฐ„ ๋ฐ•์Šค์˜ ๊ฐ’์ด ์ƒ์„ฑํ•œ ๋ด‡์˜ Token ์ž…๋‹ˆ๋‹ค. (๋‚˜์ค‘์— ํ™œ์šฉํ•ด์•ผํ•จ)

 

3. Telegram Bot “Chat ID” ํ™•์ธ ๋ฐฉ๋ฒ•

3.1 ์œ„ ์‚ฌ์ง„์˜ ์ฒซ๋ฒˆ์งธ ๋นจ๊ฐ„๋ฐ•์Šค์˜ ๋งํฌ๋ฅผ ํด๋ฆญํ•˜์—ฌ bot๊ณผ์˜ ๋Œ€ํ™”๋ฐฉ ์ด๋™! 

3.2 “์‹œ์ž‘” ์„ ๋ˆŒ๋ ค ํ™œ์„ฑํ™”

3.3 ๋ธŒ๋ผ์šฐ์ € ์ฃผ์†Œ์ฐฝ์— https://api.telegram.org/bot[๋ด‡Token๊ฐ’]/getUpdates
  https://api.telegram.org/bot5751057449:AAEtYR7ZO0nufNoB1l6kPftJI-mZQvT0Qt4/getUpdates

3.4 ์ ‘์†ํ•˜์—ฌ ์•„๋ž˜์™€ ๊ฐ™์ด ๊ฒฐ๊ณผ๊ฐ’์ด ๋‚˜์˜ค๋ฉด ์ •์ƒ

3.5 ๋Œ€ํ™”๋ฐฉ์—์„œ ์•„๋ฌด ๋ฉ”์‹œ์ง€๋‚˜ ์ž…๋ ฅ

3.5 ๋‹ค์‹œ URL ์ƒˆ๋กœ๊ณ ์นจ ํ•œ๋‹ค
      - ์ƒˆ๋กœ ์ถ”๊ฐ€๋œ ์ฝ”๋“œ์— ๋ณด์ด๋Š” ID: ๊ฐ’์ด ๋‚ด๊ฐ€ ์ง€๊ธˆ ๋ด‡์ด๋ž‘ ์ƒ์„ฑํ•œ ๋Œ€ํ™”๋ฐฉ์˜ ID ๊ฐ’์ด๋‹ค. 

 

4. Telegram ๋ฉ”์‹œ์ง€ ๋ณด๋‚ด๊ธฐ

4.1 Bot token ๊ฐ’๊ณผ chat id ๊ฐ’๋งŒ ์žˆ์œผ๋ฉด ๋œ๋‹ค!

4.2 https://api.telegram.org/bot[๋ด‡ํ† ํฐ]/sendmessage?chat_id=[์ฑ—์•„์ด๋””]&text=[๋ณด๋‚ผ๋ฉ”์‹œ์ง€]

4.3 https://api.telegram.org/bot5751057449:AAEtYR7ZO0nufNoB1l6kPftJI-mZQvT0Qt4/sendmessage?chat_id=1297136190&text="hi Maverick"

 

SOURCE

https://digitalnomad-lee.tistory.com/35

https://gabrielkim.tistory.com/entry/Telegram-Bot-Token-%EB%B0%8F-Chat-Id-%EC%96%BB%EA%B8%B0

 

 

๋‹ค์Œ๋ฒˆ์—๋Š” python + Telegram API๋ฅผ ํ™œ์šฉํ•ด์„œ bot ์•Œ๋ฆผ์„ ์ฃผ๋Š” ๋ฐฉ๋ฒ•์„ ํฌ์ŠคํŒ… ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค (โ—'โ—ก'โ—)

๋Œ“๊ธ€