joaoricardo000 / whatsapp-bot-seed

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

Command not found message #22

Closed ghost closed 8 years ago

ghost commented 8 years ago

How can i send a message if the command doesn't exist or have an invalid syntax?

ghost commented 8 years ago

Ok, i've managed to do this, it's pretty simple

In router.py:

    def route(self, message):
        "Get the text from message and tests on every route for a match"
        text = message.getBody()
        for route, callback in self.views:
            match = route.match(text)
            if match:
                threading.Thread(target=self.handle_callback, args=(callback, message, match)).start()
                return
        if text.startswith("/"):
            threading.Thread(target=self.notfound, args=(text, message)).start()

    def notfound(self, command, message):
        self.toLower(TextMessageProtocolEntity("Command \"" + command + "\" not found or invalid syntax\nType /help for the command list", to=message.getFrom()))
ghost commented 8 years ago

Take a look to my pull request

26