Skip to content

VikingsDev/Dentaku

Repository files navigation

Dentaku

Dentaku is VikingsDev's open source messenger bot.

Setting up a development environment

  1. Fork the Dentaku repository: https://github.com/VikingsDev/Dentaku.
    (If you don't know what forking is, this example could be helpful.)
  2. Clone the fork. git clone https://github.com/YOUR_GITHUB_USERNAME/Dentaku.git
    (Please input your Github username in place of YOUR_GITHUB_USERNAME.)
  3. Create a virtual environment. python -m venv venv
    (If needed, install virtualenv with pip install virtualenv.)
  4. Create an export file.
    macOS/Linux: touch export.sh
    Windows: Notepad export.sh and accept the prompt to create the new file (or create the file manually in File Explorer)
  5. Edit export.sh using a text editor, and add:
    export EMAIL="YOUR_FACEBOOK_ACCOUNT_EMAIL"
    export PASSWORD="YOUR_FACEBOOK_ACCOUNT_PASSWORD"
    export BITLY_GAT="YOUR_BITLY_GENERIC_ACCESS_TOKEN"
    export G_CREDENTIALS="PATH_TO_YOUR_SERVICE_ACCOUNT_JSON"
    

    Note: Replace the strings with your own information, but keep the quotation marks!
    Get your bit.ly Generic Access Token, which is required if you want to use commands with link shorteners.
    Get your service account credentials, which is required if you want to use commands with Google Cloud integration. This project uses Firebase.
    (Remember to hit save in the text editor before activating the variables!)

  6. Activate the venv.
    macOS/Linux: source venv/bin/activate
    Windows: venv\Scripts\activate.bat
  7. Install the required packages. pip install -r requirements.txt
  8. Run the bot. python main.py
    You should see this:
    Logging in knarf8700@gmail.com...
    Login of knarf8700@gmail.com successful.
    Testing mode will restrict all bot interactions to direct messages, or ThreadType.USER.
    Turn on testing mode? (y/n): 
    

Follow the dialog, and at the end, you should see Listening... which confirms that your bot is on and listening to Messenger.

Keep Dentaku running and check your Messenger! You should have received a message from yourself, saying "Dentaku is online." Test the 'help' command by sending !help to the chat.
Now you can make your own commands by following the guidelines below. :)

Contribution guidelines

For a full, comprehensive read on contribution, take a look at our CONTRIBUTING.md.

To add your own command, create a file named your command inside the commands folder. For example, if I wanted to make a command called dog, and I wanted users to run it as !dog, I would create a file called dog.py inside commands.

Inside dog.py, start with this template:
(Replace all occurrences of 'dog' with your command name.)

from command import Command
from fbchat import Message
from fbchat import Mention


class dog(Command):

    def run(self):
        response_text = "@" + self.author.first_name + " Hello world! This is a dog command."
        mentions = [Mention(self.author_id, length=len(self.author.first_name) + 1)]

        self.client.send(
            Message(text=response_text, mentions=mentions),
            thread_id=self.thread_id,
            thread_type=self.thread_type
        )

    def define_documentation(self):
        self.documentation = {
            "parameters": "None",
            "function": "Undefined."
        }
    

For more information on defining parameters and functions, look for the self.documentation variable on Dentaku's Wiki.

These links might be helpful:

fbchat Examples
fbchat Full Documentation

Dentaku API Documentation

Check the Wiki for API Documentation