Skip to content

Commit

Permalink
Merge pull request #94 from praekeltfoundation/fix-turn-channels
Browse files Browse the repository at this point in the history
Flip to and from around for inbound messages
  • Loading branch information
HawkiesZA authored Jan 27, 2025
2 parents 79bd1ad + 7fc8fe5 commit 3640253
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/vumi2/applications/turn_channels_api/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def turn_inbound_from_msg(message: Message, channel_id: str) -> dict:
"""
msg = {
"contact": {
"id": message.to_addr,
"profile": {"name": message.to_addr},
"id": message.from_addr,
"profile": {"name": message.from_addr},
},
"message": {
"type": "text",
Expand Down
18 changes: 12 additions & 6 deletions tests/applications/test_turn_channels_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,18 @@ def mkoutbound(
content: str, to="+1234", from_addr="+23456", reply_to="+23456", **kw
) -> dict:
return {
"block": None,
"resources": None,
"evaluated_resources": None,
"content": content,
"to": to,
"reply_to": reply_to,
"from": from_addr,
"context": {"contact": {"phone": to}},
"turn": {"text": {"body": content}},
# Turn doesn't send these fields
# "reply_to": reply_to,
# "from": from_addr,
# Context from Turn appears to be null,
# but we were expecting this to be {"contact": {"phone": to}},
"context": None,
"turn": {"type": "text", "text": {"body": content}},
**kw,
}

Expand Down Expand Up @@ -216,7 +222,7 @@ async def test_inbound_message_amqp(tca_worker, tca_ro, http_server):
assert req.path == "messages"
assert req.headers["Content-Type"] == "application/json"
assert req.body_json["message"]["text"]["body"] == "hello"
assert req.body_json["contact"]["id"] == "123"
assert req.body_json["contact"]["id"] == "456"


async def test_inbound_message(worker_factory, http_server):
Expand All @@ -235,7 +241,7 @@ async def test_inbound_message(worker_factory, http_server):
await http_server.send_rsp(RspInfo())

assert req.body_json["message"]["text"]["body"] == "hello"
assert req.body_json["contact"]["id"] == "123"
assert req.body_json["contact"]["id"] == "456"


async def test_inbound_bad_response(worker_factory, http_server, caplog):
Expand Down

0 comments on commit 3640253

Please sign in to comment.