telegram - deptno/deptno.github.io GitHub Wiki

telegram | ํ…”๋ ˆ๊ทธ๋žจ

messager

bot ๋งŒ๋“ค๊ธฐ

  1. BotFather ์™€ ๋Œ€ํ™” ์‹œ์ž‘
  • https://t.me/BotFather ์ ‘์†ํ•ด์„œ ์ ‘๊ทผ
  • telegram ์—์„œ BotFather ๊ฒ€์ƒ‰ํ•ด์„œ start
  • api token ํš๋“
  1. authorizing
  1. ๋ช…๋ น์–ด ์„ค์ •
curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"commands":[{"command": "commanda", "description": "command a"}]' \
  https://api.telegram.org/bot[token]/setMyCommands
curl https://api.telegram.org/bot[token]/getMyCommands
- https://core.telegram.org/bots/api#setchatmenubutton
  1. ์ฑ„ํŒ…
  • polling
    • telegram ์—์„œ bot ์„ ์ฐพ์•„์„œ ๋ฉ”์‹œ์ง€ ํ˜น์€ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•œ ํ›„ ์•„๋ž˜ ๋ช…๋ น์–ด๋กœ ํ™•์ธํ•œ๋‹ค
curl https://api.telegram.org/bot[token]/getUpdates
  • webhook ์‹ค์ œ ์„œ๋ฒ„๋Š” ๋ฐ˜์‘์„ฑ๊ณผ ํšจ์œจ์„ฑ์„ ์œ„ํ•ด์„œ webhook ์œผ๋กœ ์„œ๋น„์Šค ๋˜์–ด์•ผํ•œ๋‹ค
    • webhook ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” public domain ์ด ์กด์žฌํ•ด์•ผํ•˜๋ฉฐ https ๊ฐ€ ์ง€์›๋˜์–ด์•ผํ•œ๋‹ค.
      • ์‚ฌ์„ค ์ธ์ฆ์„œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ํ•ด๋‹น ์ธ์ฆ์„œ๋ฅผ ๋“ฑ๋กํ•ด์•ผํ•œ๋‹ค
    • ์ฃผ์†Œ๋กœ ํ•ด๋‹น์ด๋ฒคํŠธ๊ฐ€ ์˜ค๋ฉด ํ•ด๋‹น post ๋ฉ”์‹œ์ง€๋ฅผ ํ•ธ๋“ค๋ง ํ•˜๋ฉด๋œ๋‹ค.
  1. ์‘๋‹ตํ•˜๊ธฐ
curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"chat_id": 1830393354, "text": "hello"' \
  "https://api.telegram.org/bot[token]/sendMessage"

error

entries ์— url ์ด localhost ๋กœ ๋˜์–ด์žˆ๋Š” ๋งํฌ๋ฅผ ๊ฑธ๋ฉด ๋™์ž‘ํ•˜์ง€ ์•Š๋Š”๋‹ค.