bots para telegram ó como automatizar hasta el infinito y ... · a t a r e a o. e s bots para...

Post on 24-May-2020

29 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

atar

eao.

es

Bots para Telegramó como

automatizarhasta el infinito y más

allá.(sin morir en el intento)

atar

eao.

es

Introducción

atar

eao.

es

¿Que es un bot?● Una aplicación informática,un script, una app

dentro de otra app● Una aplicación de terceros que funciona

dentro de Telegram

atar

eao.

es

¿Que podemos hacer con un bot?● Los usuarios pueden interactuar con los

bots– Mediante mensajes

– Comandos y botones

– Con llamadas en línea

atar

eao.

es

¿Que podemos hacer con un bot?● Enviar notificaciones y noticias● Integrar otros servicios (Gmail bot, Image bot, IMDB

bot, Music bot, Wiki bot)● Herramienas personalizadas (Markdown bot, Stiker

bot, Vote bot, Like bot)● Creación de juegos (GameBot)● Servicios (HotOrBot)

atar

eao.

es

¿Como funcionan los bots?● Las peticiones que el usuario envía al bot son

procesadas por los servidores de Telegram● ¿Como nos enteramos de estas peticiones?

Dos opciones excluyentes:– Le preguntamos a Telegram: getUpdates

– Telegram nos avisa: Webhooks

atar

eao.

es

Crear un bot

atar

eao.

es

Crear un bot● Para crear un bot utilizaremos un bot.

– BotFather

● /newbot– name: Linux Center

– username: linux_center_bot

● https://t.me/linux_center_bot● Token:

716851483:AAGaXrbms19lhCbaqoR7tdCxCwvUsJtTf7c

atar

eao.

es

atar

eao.

es

Personarlizar nuestro bot● /setname para cambiar el nombre al bot● /setdescription para cambiar la descripción de

nuestro bot● /setabouttext para cambiar la información que

aparece en el acerca de● /setuserpic para cambiar la imagen de perfil de

nuestro bot

atar

eao.

es

Como interactuar con el bot● Llamadas a la API

– Agnóstico al lenguaje de programación

● getUpdates– Python – python-telegram-bot (framework)

● Webooks– Python

– PHP

atar

eao.

es

Insomnia

atar

eao.

es

Insomnia● Un cliente REST API sencillo y potente● Permite crear llamadas HTTP requests● Ver la respuesta de forma detalla● Sobre todo: ORGANIZACIÓN

atar

eao.

es

Insomnia

atar

eao.

es

Llamadas a la API

atar

eao.

es

Llamadas a la API● https://core.telegram.org/bots/api#available-

methods● getMe

– https://api.telegram.org/bot<token>/getMe

● getUpdates– https://api.telegram.org/bot<token>/getUpdates

– Nada mas crear no hay nada

atar

eao.

es

Crear un nuevo grupo● Creamos un nuevo grupo y añadimos a nuestro bot

– getUpdates se ha actualizado

● Enviemos un mensaje– https://api.telegram.org/bot <token>/sendMessage

● “chat_id”:”-123456789” / grupospublicos: @nombre– el bot tiene que ser miembro del grupo o canal.

● “text”:”Ejemplo”

atar

eao.

es

Crear un nuevo grupo● Creamos un nuevo grupo y añadimos a nuestro bot

– getUpdates se ha actualizado

● Enviemos un mensaje– https://api.telegram.org/bot <token>/sendMessage

● “chat_id”:”-123456789” / grupospublicos: @nombre– el bot tiene que ser miembro del grupo o canal.

● “text”:”Ejemplo”

atar

eao.

es

Hagamos llamadas a la API● sendMessage

– Opciones de formateado

● sendPhoto● sendAudio● sendDocument● SendVoice● Otros

atar

eao.

es

Hasta 40 llamadas a la API● getMe● sendMessage● Formatting options● forwardMessage● sendPhoto● sendAudio● sendDocument● sendVideo● sendAnimation● SendVoice

● sendVideoNote● SendMediaGroup● sendLocation● editMessageLiveLocation● stopMessageLiveLocation● sendVenue● sendContact● sendChatAction● getUserProfilePhotos● getFile

● KickChatMember● unbanChatMember● restrictChatMember● promoteChatMember● ExportChatInviteLink● setChatPhoto● deleteChatPhoto● setChatTitle● setChatDescription● pinChatMessage

● unpinChatMessage● leaveChat● getChat● getChatAdministrators● getChatMembersCount● getChatMember● setChatStickerSet● deleteChatStickerSet● answerCallbackQuery● Inline mode methods

https://core.telegram.org/bots/api#available-methods

atar

eao.

es

getUpdates

atar

eao.

es

getUpdateshttps://github.com/python-telegram-bot/python-telegram-bot/

https://github.com/atareao/senderbot

atar

eao.

es

getUpdates

https://github.com/atareao/senderbot

● Tres objetos clave– Bot. El bot �– Updater. Se encarga de interactuar con el bot

– Handler. Se encarga de interactuar con el humano

atar

eao.

es

getUpdates

https://github.com/atareao/senderbot

El bot

atar

eao.

es

getUpdates

https://github.com/atareao/senderbot

Los métodos

atar

eao.

es

getUpdates

https://github.com/atareao/senderbot

Los métodos

atar

eao.

es

getUpdates

https://github.com/atareao/senderbot

Los métodos

atar

eao.

es

getUpdates

https://github.com/atareao/senderbot

Los métodos

atar

eao.

es

getUpdates

https://github.com/atareao/senderbot

(1)

(2)

(3)

(4)

atar

eao.

es

getUpdates

https://github.com/atareao/senderbot

● Handlers– CommandHandler. Comandos

– MessageHandler. Mensajes

– ConversationHandler. Conversaciones

– CallbackQueryHandler. Respuestas

atar

eao.

esgetUpdates

https://github.com/atareao/senderbot

CommandHandler

atar

eao.

esgetUpdates

https://github.com/atareao/senderbot

CommandHandler

atar

eao.

esgetUpdates

https://github.com/atareao/senderbot

CommandHandler

atar

eao.

esgetUpdates

https://github.com/atareao/senderbot

CommandHandler

atar

eao.

esgetUpdates

https://github.com/atareao/senderbot

CommandHandler

atar

eao.

esgetUpdates

https://github.com/atareao/senderbot

MessageHandler

● Parámetros– Filters

● Filters.text● Filters.audio● Filters.photo● Filters.document● Filters.command

– callback

atar

eao.

esgetUpdates

https://github.com/atareao/senderbot

MessageHandler

atar

eao.

esgetUpdates

https://github.com/atareao/senderbot

MessageHandler

atar

eao.

esgetUpdates

https://github.com/atareao/senderbot

MessageHandler

atar

eao.

esgetUpdates

https://github.com/atareao/senderbot

MessageHandler

atar

eao.

esgetUpdates

https://github.com/atareao/senderbot

CallbackQueryHandler

atar

eao.

esgetUpdates

https://github.com/atareao/senderbot

CallbackQueryHandler

atar

eao.

esgetUpdates

https://github.com/atareao/senderbot

CallbackQueryHandler

atar

eao.

esgetUpdates

https://github.com/atareao/senderbot

CallbackQueryHandler

atar

eao.

es

Webhooks

atar

eao.

es

Webhooks

https://github.com/atareao/senderbot

● Necesitas un dominio (o ddns)● Puerto abierto

– Telegram solo trabaja con 443, 80, 88, 8443

● Cifrado SSL/TTLS (puede ser autofirmado, también Let’s Encrypt)

atar

eao.

es

Webhooks

https://github.com/atareao/senderbot

● Métodos para trabajar con tu webhook– setWebhook

– deleteWebhook

– getWebhookInfo

atar

eao.

es

Webhooks

https://github.com/atareao/senderbot

atar

eao.

es

Python

atar

eao.

es

Webhooks - Python

atar

eao.

es

Webhooks - Python

atar

eao.

es

Webhooks - Python

atar

eao.

es

Webhooks - Python

atar

eao.

es

PHP

atar

eao.

es

Webhooks - PHP2 funciones clave para las llamadas a la API

atar

eao.

es

Webhooks - PHP

atar

eao.

es

Webhooks - PHPEl web hook

(integrado con WordPress)

atar

eao.

es

Webhooks - PHPMétodos

atar

eao.

es

Recursos

atar

eao.

es

Recursos

https://github.com/atareao/senderbot

● https://www.atareao.es/tutorial/crea-tu-propio-bot-para-telegram/

● https://github.com/atareao/senderbot

● https://github.com/python-telegram-bot/python-telegram-bot/

atar

eao.

es

Agradecimientos

atar

eao.

es

Agradecimientos

top related