Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to configure more than user using telegram_send #81

Open
shukl08vk opened this issue Mar 17, 2021 · 2 comments
Open

unable to configure more than user using telegram_send #81

shukl08vk opened this issue Mar 17, 2021 · 2 comments

Comments

@shukl08vk
Copy link

shukl08vk commented Mar 17, 2021

Can anyone please tell me how to send messages to more than one user using telegram_send in python script? I didn't find any way to do that.

@bchardon
Copy link

I have the same problem, if someone has a solution I also would like to know how to deal with that.

@bchardon
Copy link

It looks like telegram-send store a single chat_id in the config file.

So I've edited the send() function of telegram_send.py to add a chat_id argument:

def send(*,
         chat_id=None, messages=None, files=None, images=None, stickers=None, animations=None, videos=None, audios=None,
         captions=None, locations=None, conf=None, parse_mode=None, silent=False, disable_web_page_preview=False,
         timeout=30):
    """Send data over Telegram. All arguments are optional.

And in the same function I've added an if statement:

if chat_id is None:
   chat_id = int(config["chat_id"]) if config["chat_id"].isdigit() else config["chat_id"]

So now I can add a specific chat_id when I send a message:
telegram_send.send(chat_id=chat_id,messages=["MyMessage"])

And I retrieve all the chat_id with:

def getchatid(token):
    url = 'https://api.telegram.org/bot'+token+'/getUpdates'
    data = requests.get(url)
    js = data.json()
    chat_id = []
    for x in js['result']:
        if 'message' in x:
            chat_id.append(x['message']['from']['id'])
    return list(set(chat_id))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants