informatica:telegram:bot
This is an old revision of the document!
Buscamos @botfather en Telegram
Escribimos
/newbot
Nos contesta:
Alright, a new bot. How are we going to call it? Please choose a name for your bot.
Ponemos el nombre del bot
jurjurbot
Nos contesta:
Good. Now let's choose a username for your bot. It must end in `bot`. Like this, for example: TetrisBot or tetris_bot.
Le ponemos:
jurjurbot
Nos dice que está creado y nos da el API del bot
Done! Congratulations on your new bot. You will find it at t.me/jurjurbot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this. Use this token to access the HTTP API: 2144753637:AAHX3BhhasddifNTDbJSvhLlYp-dGvnTxmPtk Keep your token secure and store it safely, it can be used by anyone to control your bot. For a description of the Bot API, see this page: https://core.telegram.org/bots/api
Metemos usuario en el grupo y sacamos el nombre del grupo con el comando:
curl -X GET https://api.telegram.org/bot<token>/getUpdates|jq
Por ejemplo:
curl -X GET https://api.telegram.org/bot2345053637:AAHX3BhheADTFDTDbJSvhLlYp-dGvnTxmPtk/getUpdates|jq
Nos devuelve:
"update_id": 151787201,
"message": {
"message_id": 11,
"from": {
"id": 123123123,
"is_bot": false,
"first_name": "Mi usuario telegram",
"username": "UsuarioTelegram",
"language_code": "en"
},
"chat": {
"id": -648234144,
"title": "Nombre del grupo",
"type": "group",
"all_members_are_administrators": true
},
El nombre IDl grupo es:
- 648234144
Puedo enviar un mensaje con el comando:
curl -s -X POST https://api.telegram.org/bot<TOKEN>/sendMessage -d chat_id=<CHAT_ID> -d text="prueba"
Por ejemplo:
curl -s -X POST https://api.telegram.org/bot2143367637:AAHX3BhgThifNTDbJSvhLlYp-dGvnTxmPtk/sendMessage -d chat_id=-648234144 -d text="prueba"
Podemos hacer el script:
#!/bin/bash TOKEN="2143367637:AAHX3BhgThifNTDbJSvhLlYp-dGvnTxmPtk" CHAT_ID="-648234144" URL="https://api.telegram.org/bot$TOKEN/sendMessage" curl -s -X POST $URL -d chat_id=$CHAT_ID -d text="$1"
informatica/telegram/bot.1638365878.txt.gz · Last modified: by jose
