
Security News
npm ‘is’ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
chatbot-session-flow
Advanced tools
This package provides a Django-based session management system for building a WhatsApp chatbot. It enables:
Install the package via pip:
pip install chatbot_session_flow
Set the following environment variables in your shell or a .env
file:
export pub_key=""
export secret=""
export SECRET_KEY="xx56r_@x_jb8(rqiw5+xw^+@l#m(=%9h+!98k1o$ex3_zogx"
export MODE=dev
export DEBUG=True
export DB_NAME=<dbname>
export DB_USER=<db connection user>
export DB_PASSWORD=<database password>
export DB_HOST="<database connection host>"
export DB_PORT=<database running port>
export NGUMZO_API_KEY=<your api key if using ngumzo APIs>
export DYNAMIC_METHOD_VIEWS="<your_app.dynamic_methods>"
Add it to your INSTALLED_APPS
:
INSTALLED_APPS = [
...,
'chatbot_session_flow',
]
Add middleware to enable session handling:
MIDDLEWARE = [
...,
'chatbot_session_flow.middleware.WhatsappSessionMiddleware',
]
Run the migrations:
python manage.py makemigrations chatbot_session_flow
python manage.py migrate chatbot_session_flow
The chatbot flow is managed through a sequence of Page
instances. Each page can reference the next, allowing dynamic navigation.
Sessions are tied to users via the Session
and Stepper
models.
Custom tasks such as saving data, calling APIs, or formatting messages are handled by dynamic methods specified in a dynamic file defined by DYNAMIC_METHOD_VIEWS
. These include:
sendWhatsappMessage(session, phoneNumber, message)
– your logic to send messages.formatRequest(request)
– used by middleware to shape incoming data.add_to_cart
) that can be dynamically executed.# your_app/dynamic_methods.py
def add_to_cart(session, page, message, *args, **kwargs):
print(f"Adding product to cart for user {session.user.phoneNumber}")
return "Item added to cart"
Call it dynamically:
from chatbot_session_flow.views import perform_dynamic_action
response = perform_dynamic_action(session, page, "Item name")
Use collected data within page content dynamically:
Hello {firstName}, your order has been placed!
The values in {}
are replaced by corresponding session or user data.
Handles user identity:
from chatbot_session_flow.models import Profile
profile = Profile.objects.create(
firstName="John",
lastName="Doe",
phoneNumber="+1234567890",
email="john@example.com"
)
Tracks the user’s chatbot session:
session = Session.objects.create(user=profile, isValidSession=True)
print(session.is_session_expired())
Each page drives a single step in the conversation:
page = Page.objects.create(title="Welcome", pageType="text", content="Hello {firstName}")
pip install -e .
if developing locally.python manage.py makemigrations chatbot_session_flow
python manage.py migrate
DYNAMIC_METHOD_VIEWS
is correct.task
attribute in your Page
.def custom_task(session, page, message, *args, **kwargs):
...
kamadennis05@gmail.com
This package offers a powerful framework for building WhatsApp-based conversational flows with dynamic logic and session handling. Feel free to contribute or extend the package to fit your business logic!
FAQs
A django Whatsapp chatbot session manager
We found that chatbot-session-flow demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.