Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,9 @@ def _handle_message_inbound(event: MessageInboundEvent, logger, sinch_client):
mo_text = _get_mo_text(event)
logger.info("MO SMS from %s: %s", identity, mo_text)

app_id = event.app_id
if not app_id:
logger.warning("Event has no app_id; skipping MT reply.")
return

reply_text = f"Your message said: {mo_text}"
response = sinch_client.conversation.messages.send_text_message(
app_id=app_id,
app_id=event.app_id,
text=reply_text,
recipient_identities=[{"channel": "SMS", "identity": identity}],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
class ConversationSinchEventBase(SinchEvent):
"""Base fields present on every Conversation API Sinch Event payload."""

app_id: Optional[StrictStr] = Field(
default=None,
app_id: StrictStr = Field(
description="Id of the subscribed app.",
)
project_id: Optional[StrictStr] = Field(
default=None,
project_id: StrictStr = Field(
description="The project ID of the app which has subscribed for the callback.",
)
accepted_time: Optional[datetime] = Field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def test_message_delivery_receipt_event_expects_parsed(message_delivery_report_d
def test_message_inbound_event_expects_parsed():
payload = {
"app_id": "app1",
"project_id": "proj1",
"message": {
"contact_id": "contact1",
"contact_message": {"text_message": {"text": "Hello"}},
Expand All @@ -63,6 +64,7 @@ def test_message_inbound_event_expects_parsed():
def test_message_submit_event_expects_parsed():
payload = {
"app_id": "app1",
"project_id": "proj1",
"message_submit_notification": {
"contact_id": "contact1",
"channel_identity": {"channel": "MESSENGER", "identity": "123"},
Expand All @@ -73,10 +75,10 @@ def test_message_submit_event_expects_parsed():
assert event.message_submit_notification.contact_id == "contact1"


def test_conversation_sinch_event_base_optional_fields():
payload = {"app_id": "app1"}
def test_conversation_sinch_event_base_optional_timestamp_and_metadata_fields():
payload = {"app_id": "app1", "project_id": "proj1"}
event = ConversationSinchEventBase(**payload)
assert event.app_id == "app1"
assert event.project_id is None
assert event.project_id == "proj1"
assert event.accepted_time is None
assert event.event_time is None
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ def test_parse_event_message_submit_expects_message_submit_event(conversation_si


def test_parse_event_json_string_expects_parsed(conversation_sinch_event):
payload_str = '{"app_id":"app1","message_delivery_report":{"status":"DELIVERED"}}'
payload_str = (
'{"app_id":"app1","project_id":"proj1",'
'"message_delivery_report":{"status":"DELIVERED"}}'
)
event = conversation_sinch_event.parse_event(payload_str)
assert isinstance(event, MessageDeliveryReceiptEvent)
assert event.app_id == "app1"
Expand Down
Loading