Skip to content

Commit e24e982

Browse files
committed
code review
1 parent 1c1ccbf commit e24e982

7 files changed

Lines changed: 31 additions & 31 deletions

File tree

examples/sinch_events/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This directory contains both the Event handlers and the server application (`ser
3434
```
3535
NUMBERS_WEBHOOKS_SECRET=Your Sinch Numbers Webhook Secret
3636
```
37-
- SMS controller: To configure the `sms` webhooks secret, contact your account manager to enable authentication for SMS callbacks. For more details, refer to
37+
- SMS controller: To configure the `sms` Sinch Event secret, contact your account manager to enable authentication for SMS callbacks. For more details, refer to
3838
[SMS API](https://developers.sinch.com/docs/sms/api-reference/sms/tag/Webhooks/#tag/Webhooks/section/Callbacks),
3939

4040
```
@@ -108,6 +108,6 @@ Use this value to configure the Sinch Events URLs:
108108

109109
You can also set these Sinch Events URLs in the Sinch dashboard; the API parameters above override the default values configured there.
110110

111-
> **Note**: If you have set a webhook secret (e.g., `SMS_WEBHOOKS_SECRET`), the Sinch Event URL must be configured in the Sinch dashboard
112-
> and cannot be overridden via API parameters. The webhook secret is used to validate incoming webhook requests,
111+
> **Note**: If you have set a Sinch Event secret (e.g., `SMS_WEBHOOKS_SECRET`), the Sinch Event URL must be configured in the Sinch dashboard
112+
> and cannot be overridden via API parameters. The Sinch Event secret is used to validate incoming webhook requests,
113113
> and the URL associated with it must be set in the dashboard.

examples/sinch_events/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
config = load_config()
1919
port = int(config.get('SERVER_PORT') or 3001)
2020
numbers_webhooks_secret = config.get('NUMBERS_WEBHOOKS_SECRET')
21-
sms_webhooks_secret = config.get('SMS_WEBHOOKS_SECRET')
21+
sms_sinch_event_secret = config.get('SMS_WEBHOOKS_SECRET')
2222
conversation_webhooks_secret = config.get('CONVERSATION_WEBHOOKS_SECRET')
2323
sinch_client = get_sinch_client(config)
2424

@@ -27,7 +27,7 @@
2727
sinch_client.configuration.logger.setLevel(logging.INFO)
2828

2929
numbers_controller = NumbersController(sinch_client, numbers_webhooks_secret)
30-
sms_controller = SmsController(sinch_client, sms_webhooks_secret)
30+
sms_controller = SmsController(sinch_client, sms_sinch_event_secret)
3131
conversation_controller = ConversationController(sinch_client, conversation_webhooks_secret or '')
3232

3333

examples/sinch_events/sms_api/controller.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55

66

77
class SmsController:
8-
def __init__(self, sinch_client, webhooks_secret):
8+
def __init__(self, sinch_client, sinch_event_secret):
99
self.sinch_client = sinch_client
10-
self.webhooks_secret = webhooks_secret
10+
self.sinch_event_secret = sinch_event_secret
1111
self.logger = self.sinch_client.configuration.logger
1212

1313
def sms_event(self):
1414
headers = dict(request.headers)
1515
raw_body = request.raw_body if request.raw_body else b""
1616

17-
sinch_events_service = self.sinch_client.sms.sinch_events(self.webhooks_secret)
17+
sinch_events_service = self.sinch_client.sms.sinch_events(self.sinch_event_secret)
1818

1919
# Signature headers may be absent unless your account manager enables them
2020
# (see README: Configuration -> Controller Settings -> SMS controller);

sinch/domains/sms/sinch_events/v1/events/sms_sinch_event.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class MediaBody(SinchEvent):
2525
media: conlist(MediaItem) = Field(..., description="Array of media items")
2626

2727

28-
class BaseIncomingSMSWebhookEvent(SinchEvent):
28+
class BaseIncomingSMSSinchEvent(SinchEvent):
2929
from_: StrictStr = Field(
3030
...,
3131
alias="from",
@@ -54,7 +54,7 @@ class BaseIncomingSMSWebhookEvent(SinchEvent):
5454
)
5555

5656

57-
class MOTextSinchEvent(BaseIncomingSMSWebhookEvent):
57+
class MOTextSinchEvent(BaseIncomingSMSSinchEvent):
5858
body: StrictStr = Field(
5959
...,
6060
description="The incoming message body. Maximum 2000 characters.",
@@ -64,7 +64,7 @@ class MOTextSinchEvent(BaseIncomingSMSWebhookEvent):
6464
)
6565

6666

67-
class MOBinarySinchEvent(BaseIncomingSMSWebhookEvent):
67+
class MOBinarySinchEvent(BaseIncomingSMSSinchEvent):
6868
body: StrictStr = Field(
6969
..., description="The incoming message body (Base64 encoded)."
7070
)
@@ -76,7 +76,7 @@ class MOBinarySinchEvent(BaseIncomingSMSWebhookEvent):
7676
)
7777

7878

79-
class MOMediaSinchEvent(BaseIncomingSMSWebhookEvent):
79+
class MOMediaSinchEvent(BaseIncomingSMSSinchEvent):
8080
body: MediaBody = Field(
8181
...,
8282
description="The media message body containing subject, message, and media items.",
@@ -87,11 +87,11 @@ class MOMediaSinchEvent(BaseIncomingSMSWebhookEvent):
8787

8888

8989
# Union type for isinstance checks
90-
_IncomingSMSWebhookEventUnion = Union[
90+
_IncomingSMSSinchEventUnion = Union[
9191
MOTextSinchEvent, MOBinarySinchEvent, MOMediaSinchEvent
9292
]
9393

9494
# Discriminated union for validation
9595
IncomingSMSSinchEvent = Annotated[
96-
_IncomingSMSWebhookEventUnion, Field(discriminator="type")
96+
_IncomingSMSSinchEventUnion, Field(discriminator="type")
9797
]

sinch/domains/sms/sinch_events/v1/sms_sinch_event.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
)
2222

2323

24-
SmsCallback = Union[
24+
SmsSinchEventPayload = Union[
2525
BatchDeliveryReport,
2626
RecipientDeliveryReport,
2727
MOTextSinchEvent,
@@ -64,7 +64,7 @@ def parse_event(
6464
self,
6565
event_body: Union[str, bytes, Dict[str, Any]],
6666
headers: Optional[Dict[str, str]] = None,
67-
) -> SmsCallback:
67+
) -> SmsSinchEventPayload:
6868
"""
6969
Parse the event payload into an SMS callback object.
7070
@@ -75,8 +75,8 @@ def parse_event(
7575
:type event_body: Union[str, bytes, Dict[str, Any]]
7676
:param headers: Request headers (used to decode charset when event_body is bytes).
7777
:type headers: Optional[Dict[str, str]]
78-
:returns: A parsed SMS callback object.
79-
:rtype: SmsCallback
78+
:returns: A parsed SMS Sinch Event payload object.
79+
:rtype: SmsSinchEventPayload
8080
:raises ValueError: If the event type is unknown or parsing fails.
8181
"""
8282
if isinstance(event_body, bytes):

sinch/domains/sms/sms.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ def __init__(self, sinch):
1717
self.batches = Batches(self._sinch)
1818
self.delivery_reports = DeliveryReports(self._sinch)
1919

20-
def sinch_events(self, callback_secret: str) -> SmsSinchEvent:
20+
def sinch_events(self, sinch_event_secret: str) -> SmsSinchEvent:
2121
"""
22-
Create an SMS Sinch Events handler with the specified callback secret.
22+
Create an SMS Sinch Events handler with the specified Sinch Event secret.
2323
24-
:param callback_secret: Secret used for webhook validation.
25-
:type callback_secret: str
24+
:param sinch_event_secret: Secret used for Sinch Event validation.
25+
:type sinch_event_secret: str
2626
:returns: A configured Sinch Events handler
2727
:rtype: SmsSinchEvent
2828
"""
29-
return SmsSinchEvent(callback_secret)
29+
return SmsSinchEvent(sinch_event_secret)

tests/e2e/sms/features/steps/webhooks.steps.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@
1111
)
1212
from tests.e2e.helpers import store_webhook_response
1313

14-
SINCH_SMS_CALLBACK_SECRET = 'KayakingTheSwell'
14+
SINCH_SMS_SINCH_EVENT_SECRET = 'KayakingTheSwell'
1515

1616

17-
@given('the SMS Webhooks handler is available')
17+
@given('the SMS Sinch Events handler is available')
1818
def step_webhook_handler_is_available(context):
19-
context.sms_webhook = SmsSinchEvent(SINCH_SMS_CALLBACK_SECRET)
19+
context.sms_sinch_event = SmsSinchEvent(SINCH_SMS_SINCH_EVENT_SECRET)
2020

2121

2222
@when('I send a request to trigger an "incoming SMS" event')
2323
def step_send_incoming_sms_event(context):
2424
response = requests.get('http://localhost:3017/webhooks/sms/incoming-sms')
2525
store_webhook_response(context, response)
26-
context.event = context.sms_webhook.parse_event(context.raw_event)
26+
context.event = context.sms_sinch_event.parse_event(context.raw_event)
2727

2828

2929
@then('the header of the event "{event_type}" contains a valid signature')
3030
@then('the header of the event "{event_type}" with the status "{status}" contains a valid signature')
3131
def step_check_valid_signature(context, event_type, status=None):
32-
assert context.sms_webhook.validate_authentication_header(
32+
assert context.sms_sinch_event.validate_authentication_header(
3333
context.webhook_headers, context.raw_event
3434
), 'Signature validation failed'
3535

@@ -51,7 +51,7 @@ def step_check_incoming_sms_event(context):
5151
def step_send_delivery_report_event(context):
5252
response = requests.get('http://localhost:3017/webhooks/sms/delivery-report-sms')
5353
store_webhook_response(context, response)
54-
context.event = context.sms_webhook.parse_event(context.raw_event)
54+
context.event = context.sms_sinch_event.parse_event(context.raw_event)
5555

5656

5757
@then('the SMS event describes an "SMS delivery report" event')
@@ -79,7 +79,7 @@ def step_send_recipient_delivery_report_event_delivered(context):
7979
'http://localhost:3017/webhooks/sms/recipient-delivery-report-sms-delivered'
8080
)
8181
store_webhook_response(context, response)
82-
context.event = context.sms_webhook.parse_event(context.raw_event)
82+
context.event = context.sms_sinch_event.parse_event(context.raw_event)
8383

8484

8585
@when('I send a request to trigger an "SMS recipient delivery report" event with the status "Aborted"')
@@ -88,7 +88,7 @@ def step_send_recipient_delivery_report_event_aborted(context):
8888
'http://localhost:3017/webhooks/sms/recipient-delivery-report-sms-aborted'
8989
)
9090
store_webhook_response(context, response)
91-
context.event = context.sms_webhook.parse_event(context.raw_event)
91+
context.event = context.sms_sinch_event.parse_event(context.raw_event)
9292

9393

9494
@then('the SMS event describes an SMS recipient delivery report event with the status "Delivered"')

0 commit comments

Comments
 (0)