N
N
Nomad2021-07-16 07:57:03
Python
Nomad, 2021-07-16 07:57:03

How to write several values ​​in the channel_id of a telegram bot?

def send_telegram(text: str):
    token = "token"
    url = "https://api.telegram.org/bot"
    channel_id = "123123123"
    url += token
    method = url + "/sendMessage"

    r = requests.post(method, data={
         "chat_id": channel_id,
         "text": text
          })

    if r.status_code != 200:
        raise Exception("post_text error")


How to write 3 or more values ​​in channel_id? The list did not work, separated by commas too

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nomad, 2021-11-08
@I2etr0

I did find the solution though!
Let's say that we have the following function responsible for sending the bot:

def bot1(text: str):
    token = "my_token"
    url = "https://api.telegram.org/bot"
    channel_id = "My_id"
    url += token
    method = url + "/sendMessage"

    r = requests.post(method, data={
         "chat_id": channel_id,
         "text": text
          })

    if r.status_code != 200:
        raise Exception("post_text error")

A little lower we insert the same piece, slightly modifying it:
def ище2(text: str):
    token = "my_token"
    url = "https://api.telegram.org/bot"
    channel_id = "My_id"
    url += token
    method = url + "/sendMessage"

    r = requests.post(method, data={
         "chat_id": channel_id,
         "text": text
          })

    if r.status_code != 200:
        raise Exception("post_text error")

You can also add a second person. It is necessary to replace the line with the id of the interlocutor. The ID of the interlocutor can be obtained in 2 steps: The second person must activate the bot You must follow the link https://api.telegram.org/botTOKEN/getUpdates . There you will find the id of the interlocutor . To this joy, add the following piece of code:channel_id = "My_id"


def start():
    if __name__ == '__main__':
        bot1(то_что_надо_отправить)
        bot2(то_что_надо_отправить)
    time.sleep(some_seconds)

In parentheses, you must specify either text or a variable if the data is transferred from the parser, for example
------
And, of course, run:
start()

S
soremix, 2021-07-16
@SoreMix

Not
allowed https://core.telegram.org/bots/api#sendmessage

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question