Prog MuStafa Prog MuStafa - 1 month ago 11
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 = Image.new('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
img.putdata(pixels)
output = StringIO.StringIO()
img.save(output, 'JPEG')
reply(img=output.getvalue())


When I change the code, nothing happened.

img = Image.open('image.png')
img.show()


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

Answer

The solution is

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

or

if text == 'help':
            reply(img=urllib2.urlopen('img url').read())
Comments