Giter Club home page Giter Club logo

iteam-s / ampalibe Goto Github PK

View Code? Open in Web Editor NEW
94.0 6.0 11.0 5.99 MB

Ampalibe is a lightweight Python framework for building Facebook Messenger bots faster. It provides a new concept, it manages webhooks, processes data sent by Facebook and provides API Messenger with advanced functions such as payload management, item length, and more.

Home Page: https://ampalibe.readthedocs.io/

License: MIT License

Shell 5.06% Python 93.76% Batchfile 0.94% Dockerfile 0.24%
framework python bot messenger-platform messenger-api facebook-messenger-bot facebook-messenger chatbot-framework ampalibe ampalibe-framework

ampalibe's Introduction

Ampalibe

Ampalibe is a lightweight Python framework for building Facebook Messenger bots faster. It provides a new concept, it manages webhooks, processes data sent by Facebook and provides API Messenger with advanced functions such as payload management, item length, and more.

Show your support by giving a star 🌟 if this project helped you!

Installation

pip install ampalibe

OR you can install dev version

pip install https://github.com/iTeam-S/Ampalibe/archive/refs/heads/main.zip

if you use mysql as database, you have to install mysql-connector or mysql-connector-python with ampalibe

pip install ampalibe[mysql-connector]

if you use postgresql as database, you have to install psycopg2 with ampalibe

pip install ampalibe[psycopg2]

if you use mongodb as database, you have to install pymongo with ampalibe

pip install ampalibe[pymongo]

Usage

command-line ampalibe is ampalibe.bat for Windows

ampalibe create myproject

OR

$ cd myproject
$ ampalibe init

to run project, just use

ampalibe run

for dev mode with Hot Reload

ampalibe run --dev

Register for an Access Token

You will need to configure a Facebook application, a Facebook page, get the access to the page, link the application to the page, configure a webhook for your app before you can really start using Ampalibe.

This app setup guide should help

OR

See this video on Youtube

Minimal Application

import ampalibe
from ampalibe import Messenger, Model
from ampalibe.messenger import Action

chat = Messenger()
query = Model()

@ampalibe.before_receive()
def before_process(sender_id, **ext):
    #  Mark as seen for each message received
    chat.send_action(sender_id, Action.mark_seen)
    return True

@ampalibe.command('/')
def main(sender_id, cmd, **ext):
    """
    No need to manage weebhooks and data: messages are received directly in a main function
    """
    chat.send_text(sender_id, 'Enter your name')
    
    # define the function of the next treatment
    query.set_action(sender_id, '/get_name')
    
@ampalibe.action('/get_name')
def get_name(sender_id, cmd, **ext):
    query.set_action(sender_id, None)  #  clear current action
    chat.send_text(sender_id, f'Hello {cmd}')  #  greeting with name enter by user

Documentation

Other resource

Deployment

Using container

Go to our dir project and run

$ docker run -d -v "${PWD}:/usr/src/app" -p 4555:4555 ghcr.io/iteam-s/ampalibe

Using heroku container

  • Go to heroku docs for docker deploys

  • Change your Dockerfile like this

FROM ghcr.io/iteam-s/ampalibe

ADD . /usr/src/app/

# RUN pip install --no-cache-dir -r requirements.txt

CMD ampalibe -p $PORT run
  • Customize your Dockerfile if necessary

Using heroku python

Other plateform ?

Maybe just run ampalibe run in the right directory? or specify port if needed ampalibe -p 1774 run

About

Ampalibe is a word of Malagasy origin designating the fruit jackfruit.

We have made a promise to

  • keep it light
  • make it easy to use
  • do it quickly to develop

Contributors

Image des contributeurs GitHub

Community

📌 Extension

📌 Module

📌 Star History

Star History Chart

ampalibe's People

Contributors

gaetan1903 avatar henimbola avatar rivo2302 avatar rootkit7628 avatar sergiodev22 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ampalibe's Issues

List of Features 1.0.5.dev

Discussed in https://github.com/iTeam-S/Ampalibe/discussions/25

Originally posted by gaetan1903 April 12, 2022

  • Quick Reply Auto Next for item length more than 13
  • Fix Ampalibe ASCII broken
  • Fix send_file Messenger API
  • Help Messsage for Linux
  • Docs for previous features
  • Add QuickReply Object
  • Add Button Object
  • Add Element Object
  • Customize text of next quick_reply
  • Customize text of next generic template
  • Remove mysql-connector dependancy
  • Number of processes workers in production mode
  • Persistent Menu to Object ( List Buttons )

✓ Ampalibe. TODO List

This is the list that contains all ideas about Ampalibe.

FEATURES

  • MongoDB Support
  • Items length for quick reply
  • Hot reload
  • Multi Langage Management
  • Customize Text for Next and More bouton in template and quick_reply
  • ADD Receipt Template
  • Personas Management

COMMAND LINE

  • Decorate script ampalibe for windows like Linux

  • Add a command to init only env file

    Windows & Linux doesn't have same .env file format

IMPROVEMENTS

  • Add Element Object to generate Element JSON
  • ADD Quick Rep Object to generate quick repl JSON
  • ADD kwargs for Messenger API to configure other parameters

AUTOMATION

  • Unit Test
  • Auto Release on Pypi

[IMP] UI Admin

  • Modify the "resources.py" file to include sequence parameters.
  • To improve the default view of "amp.user", allow for deletion by setting the value to TRUE and add a search panel. Additionally, update the "resources.py" file to include sequence parameters.
  • Add labels in "amp.user" column
    chrome_screenshot

[BUG] Error connection with PostgreSQL

It raises an error when connecting with psycopg2

Capture d’écran 2023-04-02 142305

And when i execute too this on my database it raises the same error:
CREATE TABLE IF NOT EXISTS "amp_user" (
id SERIAL,
user_id VARCHAR NULL DEFAULT NULL,
action TEXT NULL DEFAULT NULL,
last_use TIMESTAMP NULL DEFAULT NOW(),
lang VARCHAR NULL DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE (user_id),
INDEX (last_use)
)
Capture d’écran 2023-04-02 143616

-PostgresSQL Version 15.2

  • OS: Linux
  • Ampalibe Version 1.1.8

Tutoriel Video

  • Video General
  • Video en Anglais
  • Video en français
  • Video en Malagasy

Middleware

Add middleware for processing messages from user before handling them on the appropriated ampalibe action or command
It will be useful for interrupting process depending on the user message, like swear word warning, or switching action depending on what user input

[BUG]

Describe the bug
in CustomModel
@Model.verif_db
AttributeError: 'function' object has no attribute 'verif_db'

To Reproduce
Steps to reproduce the behavior:
Crée un class CustomModel(Model) et passer le decorateur @Model.verif_db sur les methods puis on lance Ampalibe et on obtien l'erreur "No attribute verif_db".

Raison du Bug
Dans model.py d'ampalibe on a un decorateur @singleton sur la class Model.
Si je supprime le @singleton on a plus d'erreur!

  • OS: [Linux]
  • Ampalibe Version [2.0.0-dev]

[BUG] Logger print twice a log

Describe the bug
sometimes the logger function displays the outputs twice, sometimes three times

To Reproduce

from ampalibe import Logger 

Logger.warning("it's a warning")

it's a warning
it's a warning
it's a warning



 - OS: Windows, Linux
 - Ampalibe Version 1.1.7


[BUG] Ampalibe fails when inserting users from model.py using PostgreSQL

Describe the bug
It fails even if i add users manually

Jun 16 10:12:48 PM INFO: 173.252.127.1:0 - "POST / HTTP/1.1" 500 Internal Server Error
Jun 16 10:12:48 PM ERROR: Exception in ASGI application
Jun 16 10:12:48 PM Traceback (most recent call last):
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/uvicorn/protocols/http/h11_impl.py", line 428, in run_asgi
Jun 16 10:12:48 PM result = await app( # type: ignore[func-returns-value]
Jun 16 10:12:48 PM ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in call
Jun 16 10:12:48 PM return await self.app(scope, receive, send)
Jun 16 10:12:48 PM ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/fastapi/applications.py", line 282, in call
Jun 16 10:12:48 PM await super().call(scope, receive, send)
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/starlette/applications.py", line 122, in call
Jun 16 10:12:48 PM await self.middleware_stack(scope, receive, send)
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 184, in call
Jun 16 10:12:48 PM raise exc
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 162, in call
Jun 16 10:12:48 PM await self.app(scope, receive, _send)
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 79, in call
Jun 16 10:12:48 PM raise exc
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 68, in call
Jun 16 10:12:48 PM await self.app(scope, receive, sender)
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 20, in call
Jun 16 10:12:48 PM raise e
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 17, in call
Jun 16 10:12:48 PM await self.app(scope, receive, send)
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/starlette/routing.py", line 718, in call
Jun 16 10:12:48 PM await route.handle(scope, receive, send)
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/starlette/routing.py", line 276, in handle
Jun 16 10:12:48 PM await self.app(scope, receive, send)
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/starlette/routing.py", line 66, in app
Jun 16 10:12:48 PM response = await func(request)
Jun 16 10:12:48 PM ^^^^^^^^^^^^^^^^^^^
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 241, in app
Jun 16 10:12:48 PM raw_response = await run_endpoint_function(
Jun 16 10:12:48 PM ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 167, in run_endpoint_function
Jun 16 10:12:48 PM return await dependant.call(**values)
Jun 16 10:12:48 PM ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/ampalibe/core.py", line 87, in main
Jun 16 10:12:48 PM _req._verif_user(sender_id)
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/ampalibe/model.py", line 172, in trt_verif
Jun 16 10:12:48 PM return fonction(*arg, **kwarg)
Jun 16 10:12:48 PM ^^^^^^^^^^^^^^^^^^^^^^^
Jun 16 10:12:48 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/ampalibe/model.py", line 199, in _verif_user
Jun 16 10:12:48 PM self.cursor.execute(sql, (user_id,))
Jun 16 10:12:48 PM psycopg2.errors.NotNullViolation: null value in column "user_id" of relation "amp_user" violates not-null constraint
Jun 16 10:12:48 PM DETAIL: Failing row contains (95, null, null, 2023-06-16 19:12:48.657722, null).

  • OS: Linux
  • Ampalibe Version 1.1.9

[BUG] SEND_ACTION FAILED

Description
The Function send_action doesn't work , Facebook may change the Messenger API.

Error

ERROR|Ampalibe:
  status_code : 400, data :{"error":{"message":"(#100) Sender action failed","type":"OAuthException","code":100,"error_subcode":2018048,"fbtrace_id":"AzvYcgDsCXhMQhr2K7JQIua"}}

Documentation

  • Tous les fonctions Messenger
  • Fonction Action et Command
  • Mthode Requete

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.