Pyrogram-Based Random Greeting Message Sender

  • Share this:

Code introduction


This function uses the Pyrogram library to send a random greeting message to a specified chat.


Technology Stack : Pyrogram

Code Type : Pyrogram API Function

Code Difficulty : Intermediate


                
                    
import random
from pyrogram import Client, filters

def send_random_message(client: Client, chat_id):
    """
    This function sends a random message to a specified chat using Pyrogram library.
    """
    # List of possible messages
    messages = [
        "Hello, how can I assist you today?",
        "What's up? Need any help?",
        "Hey there! How's it going?",
        "Greetings! How may I be of service?"
    ]
    
    # Select a random message from the list
    selected_message = random.choice(messages)
    
    # Send the message to the specified chat
    client.send_message(chat_id=chat_id, text=selected_message)                
              
Tags: