joaoricardo000 / whatsapp-bot-seed

A small python framework to create a whatsapp bot, with regex-callback message routing.
727 stars 245 forks source link

How can i send stored images (from the system where the bot is running)? #36

Closed x23piracy closed 8 years ago

x23piracy commented 8 years ago

Hi,

i would like to send an image before sending the text answer: return TextMessageProtocolEntity("text", to=message.getFrom())

How can i do this?

Regards X23

joaoricardo000 commented 8 years ago

Check src/utils/media_sender.py. It is simple as that:

image_sender = ImageSender(interface_layer)
image_sender.send_by_path(jid=<userjid>, path="/absolute/path/img.png", caption="optional caption")
x23piracy commented 8 years ago

Hi, how can i use this within: super_views.py?

i added in imports: ImageSender

and for class superviews: self.image_sender = ImageSender(self.interface_layer)

def info(self, message=None, match=None, to=None):
    image_sender = ImageSender(interface_layer)
    image_sender.send_by_path(jid=message.getFrom(), path="/tmp/katze.png", caption="optional caption")
    return TextMessageProtocolEntity(ABOUT_TEXT, to=message.getFrom())

Does not work:

File "/opt/whatsapp-bot-seed-master/src/router.py", line 78, in handle_callback data = callback(message, match) File "/opt/whatsapp-bot-seed-master/src/views/super_views.py", line 59, in info image_sender = ImageSender(interface_layer) NameError: global name 'interface_layer' is not defined

I am pretty new with python and my programming knowledge isn't the best, is it possible that you give me an example of the usage within super_views.py please?

Regards X23

x23piracy commented 8 years ago

Hi,

after more study i could make it work, thank you for the assistance.

Regards X23

rahulroshan96 commented 8 years ago

@x23piracy

Hi, I am getting the same error, can you please share the code, how u solved it !