I am trying to send a button in the second message but it only sends the text and not a…
- User
I am trying to send a button in the second message but it only sends the text and not a button, why is that
import asyncio import json import time from telethon import TelegramClient, errors, Button
Configuration Constants
GROUP_LINK = 'https://t.me/rocketproxyupdates' # Telegram group link BUTTON_TEXT = 'Join Our Telegram Group' # Text displayed on the button
USER_LIST_FILE = 'targets.json' SENT_FILE = 'sent.json'
Function to read API IDs and hashes from a JSON file
def read_api_config(filename): with open(filename, 'r') as f: data = json.load(f) return data['API_ID_LIST'], data['API_HASH_LIST']
Read API_ID_LIST and API_HASH_LIST from the JSON file
API_ID_LIST, API_HASH_LIST = read_api_config('clean_accounts.json')
Source chat information
FORWARD_SOURCE_CHAT_ID = 'rocketproxyupdates' # Correct group username
Alternatively, use numerical ID if preferred:
FORWARD_SOURCE_CHAT_ID = -1002325284937 # Example format for supergroups
WAIT_TIME_BASE = 1 # base wait time in seconds WAIT_TIME_FACTOR = 5 # wait time factor based on errors
async def forward_to_user(client, user, source_chat_entity, message_id): """ Forwards a message from the source chat to the target user using the provided client. """ try: # Forward the message from the source chat to the user await client.forward_messages( entity=user['username'], messages=message_id, from_peer=source_chat_entity ) print(f"Forwarded message to {user['username']} using API ID {client.api_id}") return True except errors.FloodWaitError as e: wait_time = max(WAIT_TIME_BASE, e.seconds + WAIT_TIME_FACTOR) print(f"Flood wait error: Waiting for {wait_time} seconds before retrying.") await asyncio.sleep(wait_time) return False except errors.UsernameNotOccupiedError: print(f"No user has '{user['username']}' as username.") return False except errors.PeerFloodError: print(f"Peer flood error when forwarding to '{user['username']}'.") return False except Exception as e: print(f"Failed to forward message to {user['username']}. Error: {e}") return False
async def send_button_message(client, user): """ Sends a message with an inline button linking to the Telegram group to the target user using the provided client. """ try: buttons = [ [Button.url(BUTTON_TEXT, GROUP_LINK)] ] await client.send_message( entity=user['username'], message="🔗 Stay Updated! Click the button below to join our Telegram group:", buttons=buttons ) print(f"Sent button message to {user['username']} using API ID {client.api_id}") return True except errors.FloodWaitError as e: wait_time = max(WAIT_TIME_BASE, e.seconds + WAIT_TIME_FACTOR) print(f"Flood wait error: Waiting for {wait_time} seconds before retrying.") await asyncio.sleep(wait_time) return False except errors.UsernameNotOccupiedError: print(f"No user has '{user['username']}' as username.") return False except errors.PeerFloodError: print(f"Peer flood error when sending button to '{user['username']}'.") return False except Exception as e: print(f"Failed to send button message to {user['username']}. Error: {e}") return False
- Assistant