Prog MuStafa Prog MuStafa - 1 year ago 373
Python Question

How to send an image from a telegram bot

I have my bot working by now, but the thing is it can only send text. I have seen in the Bot API there are functions to send photos, videos... but I can't get it to work. Someone has achieved it? I'm using python source code from yukuku/telebot

elif text == '/image':
img ='RGB', (512, 512))
base = random.randint(0, 16777216)
pixels = [base+i*j for i in range(512) for j in range(512)] # generate sample image
output = StringIO.StringIO(), 'JPEG')

When I change the code, nothing happened.

img ='image.png')

Please help me. I need the correct code. Sorry for my bad English.

Answer Source

The solution is

elif 'Hi' in text:
reply(img=urllib2.urlopen('img url').read())


if text == 'help':
            reply(img=urllib2.urlopen('img url').read())
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download