Python-telegram-bot: Send content to channel using bot

Created on 30 Dec 2015  路  5Comments  路  Source: python-telegram-bot/python-telegram-bot

Hi guys,

I'm newbie in telegram API, I want to send data to my channel using bot, I've already add my bot to my channel as administrator, but how can I send content via this package?

Most helpful comment

Hey :)

Check the documentation and the examples on how to send messages in general. To send a message to a channel, you can just put the name of the channel as the chat id.
Example:

bot.sendMessage(chat_id='@channelname', text='Some content')

All 5 comments

Hey :)

Check the documentation and the examples on how to send messages in general. To send a message to a channel, you can just put the name of the channel as the chat id.
Example:

bot.sendMessage(chat_id='@channelname', text='Some content')

@jh0ker yeah, I just didn't know that I have to put @channelname in chat_id param.

Thanks man :+1:

and how to send photo to channel ?
i can send text message but cant send image. i got an error that cant parse chat_id with @ symbol!

@alirezakhosraviyan

Since you're asking about posting to a channel directly from your bot, it is very important you understand that a bot needs to be made the administrator to a channel to which you'd like it to post to.

Try:

  1. Go to your channel Settings > Administrators > add your bot as Administrator
  2. now use the below code to send a photo directly to your channel

bot.sendPhoto(chat_id="_your channel name here... example: @Linuxgram", photo="https://telegram.org/img/t_logo.png", caption="Sample photo")

how can i get message from chanel. By MESSAGE ID

Was this page helpful?
0 / 5 - 0 ratings