Auto Reply No Telegram
Surgiu a necessidade de colocar um auto-reply no Telegram para avisar que agora eu estou mais presente no Discord.
Já tinha uma galera bem brava comigo por não responder PVT, sorry gente :)
Procurei em muitos lugares e acabei achando esse snippet aqui e estou usando desde então.
Basicamente é um script em Python que usa a biblioteca Telethon.
import time
from telethon import TelegramClient, events
api_id = SEU_API_ID
api_hash = 'SEU_API_HASH'
# fill in your own details here
phone = 'SEU_NUMERO_DE_TELEFONE'
session_file = './session.gutera' # use your username if unsure
password = 'SUA_SENHA' # if you have two-step verification enabled
# content of the automatic reply
message = "[guterabot] Olá, estou dando um tempo do telegram, caso precise falar comigo entre no DISCORD #BolhaTech https://abre.ai/bolhatech"
if __name__ == '__main__':
# Create the client and connect
# use sequential_updates=True to respond to messages one at a time
client = TelegramClient(session_file, api_id, api_hash, sequential_updates=True)
@client.on(events.NewMessage(incoming=True))
async def handle_new_message(event):
if event.is_private: # only auto-reply to private chats
from_ = await event.client.get_entity(event.from_id) # this lookup will be cached by telethon
if not from_.bot: # don't auto-reply to bots
print(time.asctime(), '-', event.message) # optionally log time and message
time.sleep(1) # pause for 1 second to rate-limit automatic replies
await event.respond(message)
print(time.asctime(), '-', 'Auto-replying...')
client.start(phone, password)
client.run_until_disconnected()
print(time.asctime(), '-', 'Stopped!')
É só mandar um
$ python3 nomedoarquivo.py
E pronto, auto-reply funcionando.
Refs
Gostou do conteúdo?
Você também me encontra nessas redes!
Mastodon
PixelFed
Lemmy
WriteFreely
@gutocarvalho@bolha.blog @notamental@bolha.blog @poesias@bolha.blog @contos@bolha.blog
Bookwyrm
Peertube
Friendica
Quer saber mais sobre mim?
Visite meus sites!
E meus blogs:
- https://blogs.gutocarvalho.net
- https://blogs.gutocarvalho.net/falagutera
- https://blogs.gutocarvalho.net/infra
- https://blogs.gutocarvalho.net/opiniao
- https://blogs.gutocarvalho.net/contos
- https://blogs.gutocarvalho.net/poesias
- https://blogs.gutocarvalho.net/lives
- https://blogs.gutocarvalho.net/orixas
- https://blogs.gutocarvalho.net/archives
Conhece o Coletivo Bolha?
Então vem conhecer o bolha.io ou bolhaverso!
- fediverso
- mastodon, https://bolha.us
- pixelfed, https://bolha.photos
- lemmy, https://bolha.forum
- bookwyrnm, https://bolha.review
- writefreely, https://bolha.blog
- peertube, https://bolha.tube
- castopod, https://bolha.studio
- owncast, https://bolha.stream
- friendica, https://bolha.network
- chat
- mattermost, https://mattermost.bolha.chat
- zulip, https://zulip.bolha.chat
- vídeo
- jitsi, https://bolha.video
- jitsi, https://bolha.video
- frontends
- lingva, https://translate.bolha.tools
- libremdb, https://libremdb.bolha.tools
- translations
- libretranslate, https://libretranslate.bolha.tools
- editors
- hedgedoc, https://notes.bolha.tools
- draw.io, https://draw.bolha.tools
- excalidraw, https://excalidraw.bolha.tools
- pdf stirling, https://spdf.bolha.tools
- wisemaping, https://mindmap.bolha.tools
- mermaid, https://mermaid.bolha.tools
- cryptpad, https://cryptad.bolha.tools
- secrets sharing
- yopass, https://yopass.bolha.tools
- password pusher, https://pusher.bolha.tools
- pastbin
- yabin, https://yabin.bolha.tools
- terminal recorder
- ascinnema, https://ascinemma.bolha.tools
- anti paywall
- 13ft, https://open.bolha.tools
Nós temos muito mais para compartilhar contigo!
Quer apoiar nosso trabalho? Você pode!
- https://www.patreon.com/bolha
- https://apoia.se/bolha
- pix@bolha.us
Te vejo no mastodon da bolha.us!
[s]