Skip to content

Instantly share code, notes, and snippets.

@bootell
Last active July 30, 2021 08:20
Show Gist options
  • Save bootell/a15f941ea5f148d25ba1bb4d0e14e77e to your computer and use it in GitHub Desktop.
Save bootell/a15f941ea5f148d25ba1bb4d0e14e77e to your computer and use it in GitHub Desktop.
使用云函数自动发送telegram
# -*- coding: utf-8 -*-
import time
from telethon import TelegramClient, events, sync
from telethon.sessions import StringSession
api_id = [111] #输入api_id,一个账号一项
api_hash = ['xxx'] #输入api_hash,一个账号一项
session = ['xxx']
def main_handler(event, context):
for num in range(len(api_id)):
client = TelegramClient(StringSession(session[num]), api_id[num], api_hash[num])
client.start()
entity = client.get_entity('https://t.me/boot')
client.send_message(entity, '/checkin@bot') #第一项是机器人ID,第二项是发送的文字
time.sleep(5) #延时5秒,等待机器人回应(一般是秒回应,但也有发生阻塞的可能)
client.send_read_acknowledge(entity) #将机器人回应设为已读
print("Done! Num:", num + 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment