mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-22 08:38:13 +02:00
feat: enable workflows to be embedded in websites as a script tag (#47)
* feat: add deployment configuration options * Simplify EmbedDialog * Add options for inline vs floating embedding of agent
This commit is contained in:
parent
5e4aef346d
commit
99a768f291
40 changed files with 3551 additions and 645 deletions
|
|
@ -5,15 +5,15 @@ Revises: 982ec8e434be
|
|||
Create Date: 2025-10-21 12:28:06.053318
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
from alembic_postgresql_enum import TableReference
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'a57d25b75117'
|
||||
down_revision: Union[str, None] = '982ec8e434be'
|
||||
revision: str = "a57d25b75117"
|
||||
down_revision: Union[str, None] = "982ec8e434be"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
|
@ -26,12 +26,20 @@ def upgrade() -> None:
|
|||
2. Migrates TWILIO_CONFIGURATION key to TELEPHONY_CONFIGURATION
|
||||
3. Renames twilio_status_callbacks to telephony_status_callbacks in workflow_run logs
|
||||
"""
|
||||
|
||||
|
||||
# Add 'vonage' to the workflow_run_mode enum
|
||||
op.sync_enum_values(
|
||||
enum_schema="public",
|
||||
enum_name="workflow_run_mode",
|
||||
new_values=["twilio", "stasis", "webrtc", "smallwebrtc", "VOICE", "CHAT", "vonage"],
|
||||
new_values=[
|
||||
"twilio",
|
||||
"stasis",
|
||||
"webrtc",
|
||||
"smallwebrtc",
|
||||
"VOICE",
|
||||
"CHAT",
|
||||
"vonage",
|
||||
],
|
||||
affected_columns=[
|
||||
TableReference(
|
||||
table_schema="public", table_name="workflow_runs", column_name="mode"
|
||||
|
|
@ -39,14 +47,14 @@ def upgrade() -> None:
|
|||
],
|
||||
enum_values_to_rename=[],
|
||||
)
|
||||
|
||||
|
||||
# Rename the key from TWILIO_CONFIGURATION to TELEPHONY_CONFIGURATION
|
||||
op.execute("""
|
||||
UPDATE organization_configurations
|
||||
SET key = 'TELEPHONY_CONFIGURATION'
|
||||
WHERE key = 'TWILIO_CONFIGURATION';
|
||||
""")
|
||||
|
||||
|
||||
# Rename twilio_status_callbacks to telephony_status_callbacks in workflow_run logs
|
||||
op.execute("""
|
||||
UPDATE workflow_runs
|
||||
|
|
@ -57,15 +65,17 @@ def upgrade() -> None:
|
|||
)
|
||||
WHERE logs::jsonb ? 'twilio_status_callbacks';
|
||||
""")
|
||||
|
||||
print("Migration complete: Added vonage to enum, renamed configuration key, and updated status callback keys")
|
||||
|
||||
print(
|
||||
"Migration complete: Added vonage to enum, renamed configuration key, and updated status callback keys"
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""
|
||||
Revert configuration key names and enum.
|
||||
"""
|
||||
|
||||
|
||||
# Revert telephony_status_callbacks to twilio_status_callbacks in workflow_run logs
|
||||
op.execute("""
|
||||
UPDATE workflow_runs
|
||||
|
|
@ -76,14 +86,14 @@ def downgrade() -> None:
|
|||
)
|
||||
WHERE logs::jsonb ? 'telephony_status_callbacks';
|
||||
""")
|
||||
|
||||
|
||||
# Revert key name
|
||||
op.execute("""
|
||||
UPDATE organization_configurations
|
||||
SET key = 'TWILIO_CONFIGURATION'
|
||||
WHERE key = 'TELEPHONY_CONFIGURATION';
|
||||
""")
|
||||
|
||||
|
||||
# Revert enum to previous state
|
||||
op.sync_enum_values(
|
||||
enum_schema="public",
|
||||
|
|
@ -96,5 +106,5 @@ def downgrade() -> None:
|
|||
],
|
||||
enum_values_to_rename=[],
|
||||
)
|
||||
|
||||
print("Downgrade complete: Reverted configuration key names and enum")
|
||||
|
||||
print("Downgrade complete: Reverted configuration key names and enum")
|
||||
|
|
|
|||
160
api/alembic/versions/e02f387b7538_add_embed_token_model.py
Normal file
160
api/alembic/versions/e02f387b7538_add_embed_token_model.py
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
"""add embed token model
|
||||
|
||||
Revision ID: e02f387b7538
|
||||
Revises: a57d25b75117
|
||||
Create Date: 2025-11-11 12:49:35.515641
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from alembic_postgresql_enum import TableReference
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "e02f387b7538"
|
||||
down_revision: Union[str, None] = "a57d25b75117"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table(
|
||||
"embed_tokens",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("token", sa.String(length=255), nullable=False),
|
||||
sa.Column("workflow_id", sa.Integer(), nullable=False),
|
||||
sa.Column("organization_id", sa.Integer(), nullable=False),
|
||||
sa.Column("allowed_domains", sa.JSON(), nullable=True),
|
||||
sa.Column("settings", sa.JSON(), nullable=True),
|
||||
sa.Column("is_active", sa.Boolean(), nullable=False),
|
||||
sa.Column("usage_limit", sa.Integer(), nullable=True),
|
||||
sa.Column("usage_count", sa.Integer(), nullable=False),
|
||||
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("created_by", sa.Integer(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.ForeignKeyConstraint(["created_by"], ["users.id"], ondelete="CASCADE"),
|
||||
sa.ForeignKeyConstraint(
|
||||
["organization_id"], ["organizations.id"], ondelete="CASCADE"
|
||||
),
|
||||
sa.ForeignKeyConstraint(["workflow_id"], ["workflows.id"], ondelete="CASCADE"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_embed_tokens_is_active"), "embed_tokens", ["is_active"], unique=False
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_embed_tokens_organization_id"),
|
||||
"embed_tokens",
|
||||
["organization_id"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_embed_tokens_token"), "embed_tokens", ["token"], unique=True
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_embed_tokens_workflow_id"),
|
||||
"embed_tokens",
|
||||
["workflow_id"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_table(
|
||||
"embed_sessions",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("session_token", sa.String(length=255), nullable=False),
|
||||
sa.Column("embed_token_id", sa.Integer(), nullable=False),
|
||||
sa.Column("workflow_run_id", sa.Integer(), nullable=True),
|
||||
sa.Column("client_ip", sa.String(length=45), nullable=True),
|
||||
sa.Column("user_agent", sa.String(length=500), nullable=True),
|
||||
sa.Column("origin", sa.String(length=255), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
["embed_token_id"], ["embed_tokens.id"], ondelete="CASCADE"
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["workflow_run_id"], ["workflow_runs.id"], ondelete="CASCADE"
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_embed_sessions_expires_at"),
|
||||
"embed_sessions",
|
||||
["expires_at"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_embed_sessions_session_token"),
|
||||
"embed_sessions",
|
||||
["session_token"],
|
||||
unique=True,
|
||||
)
|
||||
op.alter_column(
|
||||
"organizations",
|
||||
"quota_reset_day",
|
||||
existing_type=sa.INTEGER(),
|
||||
server_default=sa.text("1"),
|
||||
existing_nullable=False,
|
||||
)
|
||||
op.sync_enum_values(
|
||||
enum_schema="public",
|
||||
enum_name="workflow_run_mode",
|
||||
new_values=[
|
||||
"twilio",
|
||||
"vonage",
|
||||
"stasis",
|
||||
"webrtc",
|
||||
"smallwebrtc",
|
||||
"VOICE",
|
||||
"CHAT",
|
||||
],
|
||||
affected_columns=[
|
||||
TableReference(
|
||||
table_schema="public", table_name="workflow_runs", column_name="mode"
|
||||
)
|
||||
],
|
||||
enum_values_to_rename=[],
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.sync_enum_values(
|
||||
enum_schema="public",
|
||||
enum_name="workflow_run_mode",
|
||||
new_values=[
|
||||
"twilio",
|
||||
"stasis",
|
||||
"webrtc",
|
||||
"smallwebrtc",
|
||||
"VOICE",
|
||||
"CHAT",
|
||||
"vonage",
|
||||
],
|
||||
affected_columns=[
|
||||
TableReference(
|
||||
table_schema="public", table_name="workflow_runs", column_name="mode"
|
||||
)
|
||||
],
|
||||
enum_values_to_rename=[],
|
||||
)
|
||||
op.alter_column(
|
||||
"organizations",
|
||||
"quota_reset_day",
|
||||
existing_type=sa.INTEGER(),
|
||||
server_default=sa.text("LEAST((EXTRACT(day FROM CURRENT_DATE))::integer, 28)"),
|
||||
existing_nullable=False,
|
||||
)
|
||||
op.drop_index(op.f("ix_embed_sessions_session_token"), table_name="embed_sessions")
|
||||
op.drop_index(op.f("ix_embed_sessions_expires_at"), table_name="embed_sessions")
|
||||
op.drop_table("embed_sessions")
|
||||
op.drop_index(op.f("ix_embed_tokens_workflow_id"), table_name="embed_tokens")
|
||||
op.drop_index(op.f("ix_embed_tokens_token"), table_name="embed_tokens")
|
||||
op.drop_index(op.f("ix_embed_tokens_organization_id"), table_name="embed_tokens")
|
||||
op.drop_index(op.f("ix_embed_tokens_is_active"), table_name="embed_tokens")
|
||||
op.drop_table("embed_tokens")
|
||||
# ### end Alembic commands ###
|
||||
Loading…
Add table
Add a link
Reference in a new issue