danielcardeenas / whatsapp-framework

⚗️Whatsapp python api
1.16k stars 363 forks source link

Staying online while bot is running #192

Open PATAPOsha opened 6 years ago

PATAPOsha commented 6 years ago

Managed to set bot's status to online by adding make_presence() in set_entity() inside mac.py:

def set_entity(instance):
    global entity
    entity = instance
    # online(entity)                # doing nothing, don't know how to use correctly
    make_presence(entity)   # set bot status to "online" after running run.py

But when bot receives and sends message status changes to "was online ". Tried to call both make_presence() and online() inside mac.py/send_message() with no luck. Also if I try to call make_presence() directly from my module:

...
from app.mac.mac import entity

@signals.message_received.connect
def handle(message):
    mac.send_message('smth', message.conversation)

    # throws error here
    mac.make_presence(mac) # both mac and entity

it throws error:

  File "/home/pata/PycharmProjects/whatsapp-framework/modules/echo_bot/echo_bot.py", line 35, in handle
    mac.make_presence(mac)
  File "/home/pata/PycharmProjects/whatsapp-framework/app/mac/mac.py", line 69, in make_presence
    self.toLower(PresenceProtocolEntity(name=name))
AttributeError: module 'app.mac.mac' has no attribute 'toLower'

What is correct way to stay online while running bot?

PATAPOsha commented 5 years ago

Still didn't manage to solve this. Tried to call both online() and make_presence() everywhere wherever possible... as well as self.toLower(PresenceProtocolEntity(name=name)) and self.toLower(AvailablePresenceProtocolEntity())

Also noticed strange behaviour: bot's status changes to "online" on half of second at the moment bot reads the message.