Skip to content

Commit

Permalink
Flip to and from around for inbound messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit Vermeulen committed Jan 27, 2025
1 parent 79bd1ad commit dbe47d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/vumi2/applications/turn_channels_api/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ 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",
"text": {
"body": message.content,
},
"from": message.from_addr,
"from": message.to_addr,
"id": message.message_id,
"timestamp": str(int(message.timestamp.timestamp())),
},
Expand Down
17 changes: 11 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,17 @@ 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 +221,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 +240,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 dbe47d1

Please sign in to comment.