-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(telephony): add WhatsApp calling integration with outbound Calling (Business-Initiated Calling & Permission Management) #757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
amitbhakt
wants to merge
9
commits into
dograh-hq:main
Choose a base branch
from
amitbhakt:feat/whatsapp-outbound-calling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
156ad0a
feat(telephony): add WhatsApp calling integration with outbound BIC a…
amitbhakt a3682bd
fix(telephony): address review feedback on WhatsApp outbound calling …
amitbhakt 992ca1c
fix(telephony): address review feedback on rate limiter tokens, dispa…
amitbhakt 31306e1
fix(telephony): address review feedback on WhatsApp teardown, permiss…
amitbhakt c0366df
fix(telephony): canonicalize campaign numbers and drive WhatsApp UI f…
amitbhakt d604723
fix(telephony): canonical lead numbers, cancellation-safe teardown, r…
amitbhakt 4ea49d4
fix(telephony): anchor trunk-prefix stripping and surface the real ph…
amitbhakt c1dda6b
Merge remote-tracking branch 'origin/main' into feat/whatsapp-outboun…
amitbhakt 22632e8
fix(telephony): handle split country codes, require real phone-number…
amitbhakt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
api/alembic/versions/b7d2f04c8a15_index_parked_queued_runs.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| """index parked queued runs for whatsapp permission lookups | ||
|
|
||
| Revision ID: b7d2f04c8a15 | ||
| Revises: e1a2b3c4d5e6 | ||
| Create Date: 2026-09-12 10:00:00.000000 | ||
|
|
||
| """ | ||
|
|
||
| from typing import Sequence, Union | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = "b7d2f04c8a15" | ||
| down_revision: Union[str, None] = "e1a2b3c4d5e6" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| # get_queued_runs_awaiting_whatsapp_permission filters on retry_reason with | ||
| # no campaign_id, so none of the existing (campaign_id, ...) indexes apply. | ||
| # state = 'queued' is not selective on its own, which left the lookup | ||
| # scanning queued_runs on every inbound permission webhook. | ||
| op.create_index( | ||
| "idx_queued_runs_retry_reason_parked", | ||
| "queued_runs", | ||
| ["retry_reason"], | ||
| unique=False, | ||
| postgresql_where=sa.text("state = 'queued' AND retry_reason IS NOT NULL"), | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_index("idx_queued_runs_retry_reason_parked", table_name="queued_runs") | ||
59 changes: 59 additions & 0 deletions
59
api/alembic/versions/c3f5a1b90d47_index_whatsapp_perm_and_queued_run_lookups.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| """index whatsapp permission message id and workflow_runs queued_run_id | ||
|
|
||
| Revision ID: c3f5a1b90d47 | ||
| Revises: b7d2f04c8a15 | ||
| Create Date: 2026-09-12 12:00:00.000000 | ||
|
|
||
| """ | ||
|
|
||
| from typing import Sequence, Union | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = "c3f5a1b90d47" | ||
| down_revision: Union[str, None] = "b7d2f04c8a15" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| # update_whatsapp_call_permission_status_by_message_id resolves a row by | ||
| # meta_message_id alone on every permission-message status and reply | ||
| # webhook, and none of the indexes created with the table cover that | ||
| # column. meta_message_id is set once an outbound request message is sent | ||
| # and is never cleared afterward, so the partial predicate does not limit | ||
| # this to outstanding requests -- it only excludes rows that never had a | ||
| # message id attached. Not unique on purpose: the webhook path should | ||
| # degrade to an extra row rather than a write failure if Meta ever | ||
| # replays a wamid. | ||
| op.create_index( | ||
| "ix_whatsapp_perm_meta_message_id", | ||
| "whatsapp_call_permissions", | ||
| ["meta_message_id"], | ||
| unique=False, | ||
| postgresql_where=sa.text("meta_message_id IS NOT NULL"), | ||
| ) | ||
|
|
||
| # workflow_runs.queued_run_id was added as a plain foreign key in | ||
| # fefdd1835b7d; Postgres does not index the referencing side, so every | ||
| # per-lead lookup (get_workflow_run_by_queued_run_id and the campaign | ||
| # client's equivalents) scanned workflow_runs. created_at trails the key so | ||
| # the index also serves the "latest run" ORDER BY without a sort. Partial | ||
| # because only campaign-dispatched runs carry a queued_run_id and every | ||
| # caller uses equality, which never matches NULL. | ||
| op.create_index( | ||
| "idx_workflow_runs_queued_run_id", | ||
| "workflow_runs", | ||
| ["queued_run_id", "created_at"], | ||
| unique=False, | ||
| postgresql_where=sa.text("queued_run_id IS NOT NULL"), | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_index("idx_workflow_runs_queued_run_id", table_name="workflow_runs") | ||
| op.drop_index( | ||
| "ix_whatsapp_perm_meta_message_id", table_name="whatsapp_call_permissions" | ||
| ) |
125 changes: 125 additions & 0 deletions
125
api/alembic/versions/e1a2b3c4d5e6_add_whatsapp_call_permissions.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| """add whatsapp_call_permissions table | ||
|
|
||
| Revision ID: e1a2b3c4d5e6 | ||
| Revises: f3a1c47b9e02 | ||
| Create Date: 2026-09-10 15:00:00.000000 | ||
|
|
||
| """ | ||
|
|
||
| from typing import Sequence, Union | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = "e1a2b3c4d5e6" | ||
| down_revision: Union[str, None] = "f3a1c47b9e02" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.create_table( | ||
| "whatsapp_call_permissions", | ||
| sa.Column( | ||
| "id", sa.Integer(), primary_key=True, autoincrement=True, nullable=False | ||
| ), | ||
| sa.Column("organization_id", sa.Integer(), nullable=False), | ||
| sa.Column("telephony_configuration_id", sa.Integer(), nullable=False), | ||
| sa.Column("phone_number_id", sa.String(length=64), nullable=False), | ||
| sa.Column("recipient_phone_number", sa.String(length=32), nullable=False), | ||
| sa.Column( | ||
| "status", sa.String(length=32), nullable=False, server_default="pending" | ||
| ), | ||
| sa.Column("permission_type", sa.String(length=32), nullable=True), | ||
| sa.Column("meta_message_id", sa.String(length=128), nullable=True), | ||
| sa.Column( | ||
| "requested_at", | ||
| sa.DateTime(timezone=True), | ||
| nullable=False, | ||
| server_default=sa.func.now(), | ||
| ), | ||
| sa.Column("granted_at", sa.DateTime(timezone=True), nullable=True), | ||
| sa.Column("expires_at", sa.DateTime(timezone=True), nullable=True), | ||
| sa.Column( | ||
| "updated_at", | ||
| sa.DateTime(timezone=True), | ||
| nullable=False, | ||
| server_default=sa.func.now(), | ||
| ), | ||
| sa.ForeignKeyConstraint( | ||
| ["organization_id"], | ||
| ["organizations.id"], | ||
| ondelete="CASCADE", | ||
| ), | ||
| sa.ForeignKeyConstraint( | ||
| ["telephony_configuration_id"], | ||
| ["telephony_configurations.id"], | ||
| ondelete="CASCADE", | ||
| ), | ||
| sa.UniqueConstraint( | ||
| "telephony_configuration_id", | ||
| "recipient_phone_number", | ||
| name="uq_whatsapp_perm_config_recipient", | ||
| ), | ||
| ) | ||
| op.create_index( | ||
| "ix_whatsapp_call_permissions_id", | ||
| "whatsapp_call_permissions", | ||
| ["id"], | ||
| unique=False, | ||
| ) | ||
| op.create_index( | ||
| "ix_whatsapp_call_permissions_organization_id", | ||
| "whatsapp_call_permissions", | ||
| ["organization_id"], | ||
| unique=False, | ||
| ) | ||
| op.create_index( | ||
| "ix_whatsapp_call_permissions_telephony_configuration_id", | ||
| "whatsapp_call_permissions", | ||
| ["telephony_configuration_id"], | ||
| unique=False, | ||
| ) | ||
| op.create_index( | ||
| "ix_whatsapp_call_permissions_phone_number_id", | ||
| "whatsapp_call_permissions", | ||
| ["phone_number_id"], | ||
| unique=False, | ||
| ) | ||
| op.create_index( | ||
| "ix_whatsapp_call_permissions_recipient_phone_number", | ||
| "whatsapp_call_permissions", | ||
| ["recipient_phone_number"], | ||
| unique=False, | ||
| ) | ||
| op.create_index( | ||
| "ix_whatsapp_perm_lookup", | ||
| "whatsapp_call_permissions", | ||
| ["phone_number_id", "recipient_phone_number"], | ||
| unique=False, | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_index("ix_whatsapp_perm_lookup", table_name="whatsapp_call_permissions") | ||
| op.drop_index( | ||
| "ix_whatsapp_call_permissions_recipient_phone_number", | ||
| table_name="whatsapp_call_permissions", | ||
| ) | ||
| op.drop_index( | ||
| "ix_whatsapp_call_permissions_phone_number_id", | ||
| table_name="whatsapp_call_permissions", | ||
| ) | ||
| op.drop_index( | ||
| "ix_whatsapp_call_permissions_telephony_configuration_id", | ||
| table_name="whatsapp_call_permissions", | ||
| ) | ||
| op.drop_index( | ||
| "ix_whatsapp_call_permissions_organization_id", | ||
| table_name="whatsapp_call_permissions", | ||
| ) | ||
| op.drop_index( | ||
| "ix_whatsapp_call_permissions_id", table_name="whatsapp_call_permissions" | ||
| ) | ||
| op.drop_table("whatsapp_call_permissions") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: This index targets queued_runs.retry_reason, but that column is introduced by fefdd1835b7d (separate branch, down_revision a75ae71af479), which is not an ancestor of this migration. Applying this lineage on a clean database raises 'column queued_runs.retry_reason does not exist'. Set down_revision to a migration whose lineage includes the retry_reason column (merge the retry/inbound PR into this chain first), or this migration fails on fresh deploys.
Prompt for AI agents