Python

Python과 함께 텔레그램 챗봇 만들기(3)

수노 SUNHO 2019. 4. 1. 09:00
bot/ telegram bot

https://core.telegram.org/bots/api


봇은 키워드 설정을 잘해야한다 message, callback_query inline keyboard - url, callback_data


데이터를 잘 분석하여 원하는 답장 보내기 등 활용을 해야한다.


getUpdate 데이터

https://api.telegram.org/bot561471433:AAEeWZ7KdcqjYc4ujyufJHuKl8EpPQC3MdY/getUpdates

{
    "ok": true,
    "result": [
        {
            `"update_id"`: 14493917,
            "message": {
                `"message_id"`: 2,
                "from": {
                    "id": 60422092,
                    "is_bot": false,
                    "first_name": "",
                    "last_name": "",
                    "language_code": "ko-KR"
                },
                "chat": {
                    `"id"`: 60425092,
                    "first_name": "",
                    "last_name": "",
                    "type": "private"
                },
                "date": 1529892301,
                `"text"`: "nice"
            }
        }
    ]
}

polling: 특정 시간마다 계속 불러온다

Webhook이 있으나 드러워서 안써~ 느리고, 죽고.. HTTPS도 까다롭게 필요하고..




sendMessage 데이터

https://core.telegram.org/bots/api#sendmessage

https://api.telegram.org/bot561471433:AAEeWZ7KdcqjYc4ujyufJHuKl8EpPQC3MdY/sendMessage

{
    "ok": true,
    "result": {
        "message_id": 3,
        "from": {
            "id": 5611433,
            "is_bot": true,
            "first_name": "test",
            "username": "testbot"
        },
        "chat": {
            "id": 60422092,
            "first_name": "",
            "last_name": "",
            "type": "private"
        },
        "date": 15292458,
        "text": "to meet you"
    }
}