Skip to content
Daniel Cardenas edited this page Nov 20, 2016 · 7 revisions

Adding custom modules

This method will fire every time a message starting with ! is received. Take a look at layer.py (line 121).

'''
This method gets all you need in a command message.
For ex.
    In group "ITS", daniel sent "!hola a todos"
    @self = the instance (You need this to send reply with mac -> mac.send_message(instance,...))
    @command = What comes after '!'. In this case "hola"
    @predicate = What comes after command. In this case "a todos"
    @who = The jID of the person who sent this. In this case daniel (check below for retrieving the name)
    @conversation = The jId of the conversation. In this case the group "ITS".
                    NOTE: You can only send messages to conversations
'''
def handle_message(self, command, predicate, message_entity, who, conversation):

From here you add your own commands.

For example:

# Nigga who send the message (first name)
who_name = message_entity.getNotify().split(" ")[0]
if command == "hi"
    answer = "Hi *" + who_name + "*"
    mac.send_message(self, answer, conversation)

Sending messages

Right now Mac can send:

  • Text
  • Images
  • Videos

Examples:


Sending text message

  • instance: instance from handle_message()
  • answer: String to reply (Allows whatsapp format)
  • conversation: Conversation (usually the one from handle_message())
from app.mac import mac
...
mac.send_message(instance, answer, conversation)

Sending image message

  • instance: instance from handle_message()
  • conversation: Conversation (usually the one from handle_message())
  • image_path: Path to the image file
  • caption (optional): Text messsage
from app.mac import mac
...
mac.send_image(instance, conversation, image_path, caption)
Sending video message
  • instance: instance from handle_message()
  • conversation: Conversation (usually the one from handle_message())
  • image_path: Path to the video file
  • caption (optional): Text messsage
from app.mac import mac
...
mac.send_video(instance, conversation, video_path, caption)
Clone this wiki locally