Skip to main content

A package for rapidly prototyping a bot on Machaao platform

Project description

Machaao - Your one stop chatbot companion

Gitter
A module for python developers looking to rapidly build, prototype and publish personalized chatbots

Full tutorial below to create your first bot

Live Web Demo

figure

Jeanie is a GPT-J powered virtual girlfriend based on the module

Bot Creation

Create a python venv (Recommended)

# For Linux/MacOS
python3 -m venv env
source ./env/bin/activate

# For Windows
python -m venv env
env\Scripts\activate

Install machaao_client package

# For Linux/MacOS
pip3 install machaao_client

# For Windows
pip install machaao_client

Get MessengerX.io API Key

  • Available on the MessengerX.io portal
  • If you aren't registered, please create an account and login
  • Set up your new bot by providing it a Character Name and Description.
    • Select Custom Bot option
    • It should look something like this:
    • figure
  • Click on Save. It will redirect you to your dashboard.
  • On your dashboard you can see your newly created bot
    • figure
  • Click on Settings tab. It will open your bot configuration page.
    • figure
  • On the configuration page you'd be able to see a string named token. That's your Machaao API Token

Create a new .env file in the same directory

nano -w .env

Put these key-value pairs in your .env file

API_TOKEN=<Machaao API Token>
ENV=dev

Change ENV=prod when you want to publish your bot

Create a python file - app.py and copy the following code

from datetime import datetime

import pytz
from flask import Flask, request
from machaao_client import MachaaoSession, QuickReply, MachaaoTextMessage

app = Flask(__name__)


@app.route('/machaao/hook', methods=['GET', 'POST'])
def receive():
    
    # Create a machaao session
    session = MachaaoSession(
        request,
        server_session_create_time=server_session_create_time
    )

    # Get user message
    text = session.user_message
    print(f"Text from user: {text}")

    # Reply to user
    reply = "Hi from Machaao!!"

    # Add Quick replies to your message
    hello_qr = QuickReply(content_type="text", title="Hello 👋", payload="Hello")
    quick_replies = [hello_qr]

    # Compose the text message
    msg = MachaaoTextMessage(text=reply, quick_replies=quick_replies, ads=True)

    # Reply back to the user
    return session.send_message(msg)


if __name__ == '__main__':
    server_session_create_time = datetime.now(
        tz=pytz.utc).replace(tzinfo=None)

    app.run(host="0.0.0.0", port=5000, debug=False)
    

Run your simple chatbot on your local server

# For Linux/MacOS
python3 app.py

# For Windows
python app.py

Start ngrok.io tunnel in a new terminal (local development)

ngrok http 5000
  • You'll get a Forwarding URL mentioned on the console as shown below figure
  • Copy the Forwarding URL. In this example it would be:
https://26ea-150-107-177-46.ngrok-free.app

Update your webhook

Update your bot Webhook URL on the bot configuration page with the NGROK Forwarding URL
In this example your Webhook URL would be:

https://26ea-150-107-177-46.ngrok-free.app/machaao/hook

Refer to this screenshot below figure

Test your bot:

Click on Preview to chat with your bot

NOTE: UNDER ACTIVE DEVELOPMENT (ACCEPTING PULL REQUESTS)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

machaao_client-0.0.4.tar.gz (4.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

machaao_client-0.0.4-py3-none-any.whl (5.2 MB view details)

Uploaded Python 3

File details

Details for the file machaao_client-0.0.4.tar.gz.

File metadata

  • Download URL: machaao_client-0.0.4.tar.gz
  • Upload date:
  • Size: 4.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for machaao_client-0.0.4.tar.gz
Algorithm Hash digest
SHA256 7c45963267433ddd4b335c3361e887a4fe442f6fdf2171d73af7025b0f54bc40
MD5 e92f279a896e86a0e8e03bcb038bb664
BLAKE2b-256 e4dcb9573641e0f26d22c0029bc14c410c0b11cefc38b959eca972e2724711c2

See more details on using hashes here.

File details

Details for the file machaao_client-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: machaao_client-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for machaao_client-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 234a2381b5d776dd63b8f828b03d77117857e3eb5a7a5b7e70d750e88f93dc59
MD5 97253f5e442b0062fbab6ada9e64a50a
BLAKE2b-256 5fed73a095b03c2650d8510ff4d1ca4524c85e1cadf891cef9f9b5eb3642c3a0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page