Skip to main content

Python IVR flow for Yemot HaMashiach

Project description

-----------------------------

File: README.md

-----------------------------

yemot_router – ספריית Flow לפייתון עבור ימות המשיח

גרסה 0.1 • רישיון MIT

yemot_router (להלן Yemot Flow) מאפשרת לכתוב מערכות IVR מורכבות ל‑ימות המשיח בפייתון — בקוד נקי, רציף, וללא כתיבת מחרוזות API ידנית. הספרייה שואבת השראה מה‑Node‑js ‎yemot-router2 ומספקת ממשק דומה (ואף משופר) למפתחים בפייתון.


תכונות מרכזיות

✔︎ תכונה פירוט
קוד לינארי כיתות Flow ו‑Call מחזיקות מצב (state) בין קריאות HTTP, כך שהקוד שלך נראה כמו סקריפט רציף אחד.
אינטגרציה קלה עובד עם Flask או FastAPI בכמה שורות קוד.
API קריא מתודות גבוהות‑רמה (read, play_message, goto, hangup) שבונות אוטומטית את תגובת הטקסט לימות.
ניהול תקלות timeout מובנה לניקוי שיחות תקועות, ולכידת חריגות עם הודעת ברירת‑מחדל למתקשר.
דוגמאות וטסטים קוד מלא לדוגמה (Flask / FastAPI) ובדיקות pytest בסיסיות לשימוש מיידי.

התקנה

pip install yemot_router flask            # עבור Flask
# או:
pip install yemot_router fastapi uvicorn  # עבור FastAPI

הספרייה דורשת Python 3.10 ומעלה.


דוגמת Flask מהירה

from flask import Flask, request, Response
from yemot_router import Flow

app = Flask(__name__)
flow = Flow(print_log=True)  # הדפסת לוג לפיתוח

@flow.get("")  # שלוחה ראשית /
def welcome(call):
    call.play_message([("text", "שלום וברכה! להמשך – הקש 1")])
    call.read([("text", "הקש 1 להמשך")], max_digits=1, digits_allowed="1")
    if call.params.get("Digits") == "1":
        call.goto("/thanks")

@flow.get("thanks")
def thanks(call):
    call.play_message([("text", "תודה ולהתראות")])
    call.hangup()

@app.route("/yemot", methods=["GET", "POST"])
def yemot_entry():
    resp = flow.handle_request(request.values.to_dict())
    return Response(resp, mimetype="text/plain; charset=utf-8")

if __name__ == "__main__":
    app.run(port=5000)
  • כוון ב‑ימות את כתובת API ל‑http://<server‑ip>:5000/yemot.
  • הפעל את הסקריפט ושמע את ההודעה בטלפון.

דוגמת FastAPI מהירה

from fastapi import FastAPI, Request, Response
from yemot_router import Flow

app = FastAPI()
flow = Flow()

@flow.get("")
def root(call):
    call.play_message([("text", "שלום מ‑FastAPI!")])
    call.hangup()

@app.api_route("/yemot", methods=["GET", "POST"])
async def yemot_entry(request: Request):
    params = await request.form() if request.method == "POST" else request.query_params
    resp = flow.handle_request(dict(params))
    return Response(resp, media_type="text/plain; charset=utf-8")

הרץ עם uvicorn main:app --host 0.0.0.0 --port 8000.


מבנה הפרויקט

yemot_router/
├── __init__.py      # ייצוא Flow ו‑Call
├── flow.py          # ניהול שיחות ומיפוי שלוחות → handlers
├── call.py          # אובייקט שיחה: read / play_message / goto וכו׳
├── actions.py       # מחוללי‑טקסט נמוכי‑רמה לתגובת API
└── utils.py         # עזר: קידוד URL, ניקוי תווים, timestamp
examples/
├── flask_app_example.py
└── fastapi_app_example.py
tests/
└── test_basic_flow.py
pyproject.toml        # מידע התקנה ותלויות

API עיקרי

Flow

flow = Flow(timeout=30000, print_log=True)
flow.get("/sales")(sales_handler)  # רישום שלוחה
  • timeout – מילישניות לפני ששיחה לא פעילה נמחקת (ברירת‑מחדל: 30 שניות).
  • print_log – הפעלת לוג INFO אוטומטי לניפוי שגיאות.

Call (עבור כל שיחה)

מתודה שימוש
play_message(messages) השמעת הודעות (טקסט, קובץ, ספרות, מספר וכו׳).
read(messages, mode="tap", **options) בקשת קלט מהמשתמש: מקשים (tap), זיהוי דיבור (stt) או הקלטה (record).
goto(folder) מעבר לשלוחה אחרת או hangup לניתוק.
hangup() קיצור ל‑goto("hangup").

פורמט הודעה

("text", "שלום")
("file", "welcome")
("digits", "1234")

ניהול שיחות (State)

  • מזהה השיחה ApiCallId משמש כמפתח באובייקט active_calls‎.
  • כל שיחה מחזיקה את last_activity_ms; אם עובר זמן timeout ללא תנועה — השיחה נמחקת מזיכרון.
  • בקשת hangup=yes מוחקת מיד את השיחה.

בדיקות

pytest -q tests

הבדיקות מדמות קריאה מ‑Yemot ומוודאות שהתגובה בפורמט תקין.


תוכנית פיתוח עתידית

  • ✨ תמיכה מלאה ב‑stt ו‑record (זיהוי דיבור והקלטה).
  • ✨ ממשק פלאגינים (סליקת אשראי, TTS חיצוני, WebSocket Debug).
  • ✨ CLI ליצירת פרויקט חדש במהירות.

תרומות, Pull‑Requests ושאלות–בפורום ימות או ב‑GitHub. 🙌


רישיון

MIT License – עשה כרצונך, קרדיט יתקבל באהבה.

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

yemot_flow-0.1.2.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

yemot_flow-0.1.2-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file yemot_flow-0.1.2.tar.gz.

File metadata

  • Download URL: yemot_flow-0.1.2.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for yemot_flow-0.1.2.tar.gz
Algorithm Hash digest
SHA256 13ffc29fd2ec0cb50231e92dfd668ca4e902e42e5fd283e28dc0952a3b37bbf3
MD5 c07f8c11609877b1594ad7d1fb856624
BLAKE2b-256 927d3cb9702f3fed133706801353b096ac9d4fd4bd1ff97d78f10fb8fa513de3

See more details on using hashes here.

File details

Details for the file yemot_flow-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: yemot_flow-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for yemot_flow-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 244f7b6f0cba85b54976760f8a64890da69ea6b71a5fda4eb3dc72641a3fa5f7
MD5 4f992e8550d2f6e7428b1cda0ea25b25
BLAKE2b-256 37f49dbe02bbdf6a8190fc030e5ed96da71324d02725a61221b94d203ee8cc59

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