Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/webhooks/sms_api/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def sms_event(self):
headers = dict(request.headers)
raw_body = request.raw_body if request.raw_body else b""

webhooks_service = self.sinch_client.sms.webhooks(self.webhooks_secret)
webhooks_service = self.sinch_client.sms.sinch_events(self.webhooks_secret)

# Signature headers may be absent unless your account manager enables them
# (see README: Configuration -> Controller Settings -> SMS controller);
Expand Down
4 changes: 2 additions & 2 deletions examples/webhooks/sms_api/server_business_logic.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from sinch.domains.sms.webhooks.v1.events.sms_webhooks_event import IncomingSMSWebhookEvent
from sinch.domains.sms.sinch_events.v1.events.sms_sinch_event import IncomingSMSWebhookEvent


def handle_sms_event(sms_event: IncomingSMSWebhookEvent, logger):
"""
This method handles an SMS event.
Args:
sms_event (SmsWebhooksEvent): The SMS event data.
sms_event (IncomingSMSWebhookEvent): The SMS event data.
logger (logging.Logger, optional): Logger instance for logging. Defaults to None.
"""
logger.info(f'Handling SMS event:\n{sms_event.model_dump_json(indent=2)}')
96 changes: 48 additions & 48 deletions sinch/domains/sms/api/v1/batches_apis.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ class UpdateBinaryRequest(BaseModelConfigurationRequest):
default=None,
description="If set, the system will stop trying to deliver the message at this point. Constraints: Must be after `send_at` Default: 3 days after `send_at` ",
)
callback_url: Optional[StrictStr] = Field(
event_destination_target: Optional[StrictStr] = Field(
default=None,
alias="callback_url",
description="Override the default callback URL for this batch. Constraints: Must be valid URL. ",
)
client_reference: Optional[StrictStr] = Field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class UpdateMediaRequest(BaseModelConfigurationRequest):
default=None,
description="If set, the system will stop trying to deliver the message at this point. Constraints: Must be after `send_at` Default: 3 days after `send_at` ",
)
callback_url: Optional[StrictStr] = Field(
event_destination_target: Optional[StrictStr] = Field(
default=None,
alias="callback_url",
description="Override the default callback URL for this batch. Constraints: Must be valid URL. ",
)
client_reference: Optional[StrictStr] = Field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ class UpdateTextRequest(BaseModelConfigurationRequest):
default=None,
description="If set, the system will stop trying to deliver the message at this point. Constraints: Must be after `send_at` Default: 3 days after `send_at` ",
)
callback_url: Optional[StrictStr] = Field(
event_destination_target: Optional[StrictStr] = Field(
default=None,
alias="callback_url",
description="Override the default callback URL for this batch. Constraints: Must be valid URL. ",
)
client_reference: Optional[StrictStr] = Field(
Expand Down
3 changes: 2 additions & 1 deletion sinch/domains/sms/models/v1/shared/binary_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ class BinaryRequest(BaseModelConfigurationRequest):
default=None,
description="If set, the system will stop trying to deliver the message at this point. Must be after `send_at`. Default and max is 3 days after `send_at`. Formatted as [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601). For example: `YYYY-MM-DDThh:mm:ss.SSSZ`.",
)
callback_url: Optional[StrictStr] = Field(
event_destination_target: Optional[StrictStr] = Field(
default=None,
alias="callback_url",
description="Override the *default* callback URL for this batch. Must be a valid URL. Learn how to set a default callback URL [here](https://community.sinch.com/t5/SMS/How-do-I-assign-a-callback-URL-to-an-SMS-service-plan/ta-p/8414).",
)
client_reference: Optional[StrictStr] = Field(
Expand Down
6 changes: 4 additions & 2 deletions sinch/domains/sms/models/v1/shared/binary_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ class BinaryResponse(BaseModelConfigurationResponse):
default=None,
description="If set, the date and time the message will expire. Formatted as [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601). For example: `YYYY-MM-DDThh:mm:ss.SSSZ`.",
)
callback_url: Optional[StrictStr] = Field(
default=None, description="The callback URL provided in the request."
event_destination_target: Optional[StrictStr] = Field(
default=None,
alias="callback_url",
description="The callback URL provided in the request.",
)
client_reference: Optional[StrictStr] = Field(
default=None,
Expand Down
3 changes: 2 additions & 1 deletion sinch/domains/sms/models/v1/shared/media_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ class MediaRequest(BaseModelConfigurationRequest):
default=None,
description="If set, the system will stop trying to deliver the message at this point. Must be after `send_at`. Default and max is 3 days after `send_at`. Formatted as [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601): `YYYY-MM-DDThh:mm:ss.SSSZ`. ",
)
callback_url: Optional[StrictStr] = Field(
event_destination_target: Optional[StrictStr] = Field(
default=None,
alias="callback_url",
description="Override the default callback URL for this batch. Must be valid URL.",
)
client_reference: Optional[StrictStr] = Field(
Expand Down
3 changes: 2 additions & 1 deletion sinch/domains/sms/models/v1/shared/media_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ class MediaResponse(BaseModelConfigurationResponse):
default=None,
description="If set the system will stop trying to deliver the message at this point. Must be after `send_at`. Default and max is 3 days after send_at. YYYY-MM-DDThh:mm:ss.SSSZ format",
)
callback_url: Optional[StrictStr] = Field(
event_destination_target: Optional[StrictStr] = Field(
default=None,
alias="callback_url",
description="Override the default callback URL for this batch. Must be valid URL.",
)
client_reference: Optional[StrictStr] = Field(
Expand Down
3 changes: 2 additions & 1 deletion sinch/domains/sms/models/v1/shared/text_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ class TextRequest(BaseModelConfigurationRequest):
default=None,
description="If set, the system will stop trying to deliver the message at this point. Must be after `send_at`. Default and max is 3 days after `send_at`. Formatted as [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601): `YYYY-MM-DDThh:mm:ss.SSSZ`.",
)
callback_url: Optional[StrictStr] = Field(
event_destination_target: Optional[StrictStr] = Field(
default=None,
alias="callback_url",
description="Override the *default* callback URL for this batch. Must be a valid URL. Learn how to set a default callback URL [here](https://community.sinch.com/t5/SMS/How-do-I-assign-a-callback-URL-to-an-SMS-service-plan/ta-p/8414).",
)
client_reference: Optional[StrictStr] = Field(
Expand Down
3 changes: 2 additions & 1 deletion sinch/domains/sms/models/v1/shared/text_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ class TextResponse(BaseModelConfigurationResponse):
default=None,
description="If set, the system will stop trying to deliver the message at this point. Must be after `send_at`. Default and max is 3 days after `send_at`. Formatted as [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601): `YYYY-MM-DDThh:mm:ss.SSSZ`.",
)
callback_url: Optional[StrictStr] = Field(
event_destination_target: Optional[StrictStr] = Field(
default=None,
alias="callback_url",
description="Override the default callback URL for this batch. Must be valid URL.",
)
client_reference: Optional[StrictStr] = Field(
Expand Down
5 changes: 5 additions & 0 deletions sinch/domains/sms/sinch_events/v1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from sinch.domains.sms.sinch_events.v1.sms_sinch_event import (
SmsSinchEvent,
)

__all__ = ["SmsSinchEvent"]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sinch.domains.sms.webhooks.v1.events.sms_webhooks_event import (
from sinch.domains.sms.sinch_events.v1.events.sms_sinch_event import (
IncomingSMSWebhookEvent,
MOTextWebhookEvent,
MOBinaryWebhookEvent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime
from typing import Optional, Union, Literal, Annotated
from pydantic import Field, StrictStr, StrictInt, conlist
from sinch.domains.sms.webhooks.v1.internal import WebhookEvent
from sinch.domains.sms.sinch_events.v1.internal import WebhookEvent


class MediaItem(WebhookEvent):
Expand Down
5 changes: 5 additions & 0 deletions sinch/domains/sms/sinch_events/v1/internal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from sinch.domains.sms.sinch_events.v1.internal.webhook_event import (
WebhookEvent,
)

__all__ = ["WebhookEvent"]
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
parse_json,
normalize_iso_timestamp,
)
from sinch.domains.sms.webhooks.v1.events import (
from sinch.domains.sms.sinch_events.v1.events import (
IncomingSMSWebhookEvent,
MOTextWebhookEvent,
MOBinaryWebhookEvent,
Expand All @@ -30,7 +30,7 @@
]


class SmsWebhooks:
class SmsSinchEvent:
def __init__(self, app_secret: Optional[str] = None):
self.app_secret = app_secret

Expand Down
12 changes: 6 additions & 6 deletions sinch/domains/sms/sms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Batches,
DeliveryReports,
)
from sinch.domains.sms.webhooks.v1.sms_webhooks import SmsWebhooks
from sinch.domains.sms.sinch_events.v1.sms_sinch_event import SmsSinchEvent


class SMS:
Expand All @@ -17,13 +17,13 @@ def __init__(self, sinch):
self.batches = Batches(self._sinch)
self.delivery_reports = DeliveryReports(self._sinch)

def webhooks(self, callback_secret: str) -> SmsWebhooks:
def sinch_events(self, callback_secret: str) -> SmsSinchEvent:
"""
Create an SMS webhooks handler with the specified callback secret.
Create an SMS Sinch Events handler with the specified callback secret.

:param callback_secret: Secret used for webhook validation.
:type callback_secret: str
:returns: A configured webhooks handler
:rtype: SmsWebhooks
:returns: A configured Sinch Events handler
:rtype: SmsSinchEvent
"""
return SmsWebhooks(callback_secret)
return SmsSinchEvent(callback_secret)
5 changes: 0 additions & 5 deletions sinch/domains/sms/webhooks/v1/internal/__init__.py

This file was deleted.

6 changes: 3 additions & 3 deletions tests/e2e/sms/features/steps/webhooks.steps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import requests
from datetime import datetime, timezone
from behave import given, when, then
from sinch.domains.sms.webhooks.v1.sms_webhooks import SmsWebhooks
from sinch.domains.sms.webhooks.v1.events import (
from sinch.domains.sms.sinch_events.v1.sms_sinch_event import SmsSinchEvent
from sinch.domains.sms.sinch_events.v1.events import (
MOTextWebhookEvent,
)
from sinch.domains.sms.models.v1.response import (
Expand All @@ -16,7 +16,7 @@

@given('the SMS Webhooks handler is available')
def step_webhook_handler_is_available(context):
context.sms_webhook = SmsWebhooks(SINCH_SMS_CALLBACK_SECRET)
context.sms_webhook = SmsSinchEvent(SINCH_SMS_CALLBACK_SECRET)


@when('I send a request to trigger an "incoming SMS" event')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ def test_request_body_expects_text_request_data(text_request_data):
assert body["body"] == "Your verification code is 123456"


def test_request_body_uses_callback_url_alias_for_event_destination_target():
"""Ensure event_destination_target is serialized as backend callback_url."""
request = TextRequest(
to=["+46701234567"],
from_="+46701111111",
body="Hello",
event_destination_target="https://example.com/callback",
)
endpoint = SendSMSEndpoint("test_project_id", request)
body = json.loads(endpoint.request_body())

assert body["callback_url"] == "https://example.com/callback"
assert "event_destination_target" not in body


def test_request_body_expects_binary_request_data(binary_request_data):
"""Test that binary request body contains correct fields."""
endpoint = SendSMSEndpoint("test_project_id", binary_request_data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_dry_run_text_request_expects_valid_inputs_and_all_fields(
delivery_report="summary",
send_at=send_at,
expire_at=expire_at,
callback_url="https://capybara.com/callback",
event_destination_target="https://capybara.com/callback",
client_reference="test-ref",
feedback_enabled=True,
flash_message=False,
Expand All @@ -134,7 +134,7 @@ def test_dry_run_text_request_expects_valid_inputs_and_all_fields(
assert request.delivery_report == "summary"
assert request.send_at == send_at
assert request.expire_at == expire_at
assert request.callback_url == "https://capybara.com/callback"
assert request.event_destination_target == "https://capybara.com/callback"
assert request.client_reference == "test-ref"
assert request.feedback_enabled is True
assert request.flash_message is False
Expand Down Expand Up @@ -191,7 +191,7 @@ def test_dry_run_binary_request_expects_valid_inputs_and_all_fields(
delivery_report="full",
send_at=send_at,
expire_at=expire_at,
callback_url="https://capybara.com/callback",
event_destination_target="https://capybara.com/callback",
client_reference="binary-ref",
feedback_enabled=False,
from_ton=0,
Expand All @@ -203,7 +203,7 @@ def test_dry_run_binary_request_expects_valid_inputs_and_all_fields(
assert request.delivery_report == "full"
assert request.send_at == send_at
assert request.expire_at == expire_at
assert request.callback_url == "https://capybara.com/callback"
assert request.event_destination_target == "https://capybara.com/callback"
assert request.client_reference == "binary-ref"
assert request.feedback_enabled is False
assert request.from_ton == 0
Expand Down Expand Up @@ -256,7 +256,7 @@ def test_dry_run_media_request_expects_valid_inputs_and_all_fields(
delivery_report="summary",
send_at=send_at,
expire_at=expire_at,
callback_url="https://capybara.com/callback",
event_destination_target="https://capybara.com/callback",
client_reference="media-ref",
feedback_enabled=True,
)
Expand All @@ -266,7 +266,7 @@ def test_dry_run_media_request_expects_valid_inputs_and_all_fields(
assert request.delivery_report == "summary"
assert request.send_at == send_at
assert request.expire_at == expire_at
assert request.callback_url == "https://capybara.com/callback"
assert request.event_destination_target == "https://capybara.com/callback"
assert request.client_reference == "media-ref"
assert request.feedback_enabled is True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_replace_binary_request_expects_valid_inputs_and_all_fields(
delivery_report="summary",
send_at=send_at,
expire_at=expire_at,
callback_url="https://capybara.com/callback",
event_destination_target="https://capybara.com/callback",
client_reference="test-ref",
feedback_enabled=True,
from_ton=1,
Expand All @@ -49,7 +49,7 @@ def test_replace_binary_request_expects_valid_inputs_and_all_fields(
assert request.delivery_report == "summary"
assert request.send_at == send_at
assert request.expire_at == expire_at
assert request.callback_url == "https://capybara.com/callback"
assert request.event_destination_target == "https://capybara.com/callback"
assert request.client_reference == "test-ref"
assert request.feedback_enabled is True
assert request.from_ton == 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_replace_media_request_expects_valid_inputs_and_all_fields(
delivery_report="full",
send_at=send_at,
expire_at=expire_at,
callback_url="https://capybara.com/webhook",
event_destination_target="https://capybara.com/webhook",
client_reference="capybara-media-batch-123",
feedback_enabled=True,
strict_validation=True,
Expand All @@ -62,7 +62,7 @@ def test_replace_media_request_expects_valid_inputs_and_all_fields(
assert request.delivery_report == "full"
assert request.send_at == send_at
assert request.expire_at == expire_at
assert request.callback_url == "https://capybara.com/webhook"
assert request.event_destination_target == "https://capybara.com/webhook"
assert request.client_reference == "capybara-media-batch-123"
assert request.feedback_enabled is True
assert request.strict_validation is True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_update_binary_request_expects_valid_inputs_and_all_fields(
delivery_report="full",
send_at=send_at,
expire_at=expire_at,
callback_url="https://capybara.com/binary-callback",
event_destination_target="https://capybara.com/binary-callback",
client_reference="binary-update-456",
feedback_enabled=True,
from_ton=3,
Expand All @@ -52,7 +52,7 @@ def test_update_binary_request_expects_valid_inputs_and_all_fields(
assert request.delivery_report == "full"
assert request.send_at == send_at
assert request.expire_at == expire_at
assert request.callback_url == "https://capybara.com/binary-callback"
assert request.event_destination_target == "https://capybara.com/binary-callback"
assert request.client_reference == "binary-update-456"
assert request.feedback_enabled is True
assert request.from_ton == 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_update_media_request_expects_valid_inputs_and_all_fields(
delivery_report="none",
send_at=send_at,
expire_at=expire_at,
callback_url="https://capybara.com/media-callback",
event_destination_target="https://capybara.com/media-callback",
client_reference="media-update-789",
feedback_enabled=True,
strict_validation=True,
Expand All @@ -62,7 +62,7 @@ def test_update_media_request_expects_valid_inputs_and_all_fields(
assert request.delivery_report == "none"
assert request.send_at == send_at
assert request.expire_at == expire_at
assert request.callback_url == "https://capybara.com/media-callback"
assert request.event_destination_target == "https://capybara.com/media-callback"
assert request.client_reference == "media-update-789"
assert request.feedback_enabled is True
assert request.strict_validation is True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_update_text_request_expects_valid_inputs_and_all_fields(
delivery_report="summary",
send_at=send_at,
expire_at=expire_at,
callback_url="https://capybara.com/webhook",
event_destination_target="https://capybara.com/webhook",
client_reference="update-ref-123",
feedback_enabled=True,
flash_message=True,
Expand All @@ -54,7 +54,7 @@ def test_update_text_request_expects_valid_inputs_and_all_fields(
assert request.delivery_report == "summary"
assert request.send_at == send_at
assert request.expire_at == expire_at
assert request.callback_url == "https://capybara.com/webhook"
assert request.event_destination_target == "https://capybara.com/webhook"
assert request.client_reference == "update-ref-123"
assert request.feedback_enabled is True
assert request.flash_message is True
Expand Down
Loading
Loading