Skip to content

Commit 70a1247

Browse files
authored
DEVEXP-794: Conversation Messages Send - Snippets (#118)
1 parent 8da74b9 commit 70a1247

12 files changed

Lines changed: 780 additions & 0 deletions

File tree

MIGRATION_GUIDE.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,39 @@ sinch_client = SinchClient(
9393
sinch_client.configuration.conversation_region = "eu"
9494
```
9595

96+
### [`Conversation`](https://github.com/sinch/sinch-sdk-python/tree/main/sinch/domains/conversation)
97+
98+
#### Replacement models
99+
100+
##### Messages (send, get, delete, list)
101+
102+
| Old class | New class |
103+
|-----------|-----------|
104+
| `sinch.domains.conversation.models.message.requests.SendConversationMessageRequest` | `send()`: pass `app_id`, `message` (dict or [`SendMessageRequestBodyDict`](sinch/domains/conversation/models/v1/messages/types/send_message_request_body_dict.py)), and either `contact_id` or `recipient_identities`. Internally uses [`SendMessageRequest`](sinch/domains/conversation/models/v1/messages/internal/request/send_message_request.py), [`SendMessageRequestBody`](sinch/domains/conversation/models/v1/messages/internal/request/send_message_request_body.py). For typed payloads use `send_text_message()`, `send_card_message()`, etc.
105+
| `sinch.domains.conversation.models.message.responses.SendConversationMessageResponse` | [`SendMessageResponse`](sinch/domains/conversation/models/v1/messages/response/types/send_message_response.py) (`message_id`, optional `accepted_time` as `datetime`) |
106+
| `sinch.domains.conversation.models.message.requests.GetConversationMessageRequest` | `get(message_id, messages_source=None, **kwargs)`. Internally uses [`MessageIdRequest`](sinch/domains/conversation/models/v1/messages/internal/request/message_id_request.py). |
107+
| `sinch.domains.conversation.models.message.responses.GetConversationMessageResponse` | [`ConversationMessageResponse`](sinch/domains/conversation/models/v1/messages/response/types/__init__.py) (Union of app/contact message response types) |
108+
| `sinch.domains.conversation.models.message.requests.DeleteConversationMessageRequest` | `delete(message_id, messages_source=None, **kwargs)`. Internally uses [`MessageIdRequest`](sinch/domains/conversation/models/v1/messages/internal/request/message_id_request.py). |
109+
| `sinch.domains.conversation.models.message.responses.DeleteConversationMessageResponse` | `None` (method returns `None`) |
110+
| `sinch.domains.conversation.models.message.requests.ListConversationMessagesRequest` | `list()` with individual parameters: `conversation_id`, `contact_id`, `app_id`, `page_size`, `page_token`, `view`, `messages_source`, `only_recipient_originated` (signature aligned with V1 where available) |
111+
| `sinch.domains.conversation.models.message.responses.ListConversationMessagesResponse` | Response type for `list()` (messages list, next_page_token) |
112+
113+
#### Replacement APIs
114+
115+
The Conversation domain API access remains `sinch_client.conversation`; message operations are under `sinch_client.conversation.messages`. Recipient is specified with exactly one of `contact_id` or `recipient_identities` (list of `{channel, identity}`).
116+
117+
##### Messages API
118+
119+
| Old method | New method in `conversation.messages` |
120+
|------------|----------------------------------------|
121+
| `send()` with `SendConversationMessageRequest` | Use convenience methods: `send_text_message()`, `send_card_message()`, `send_carousel_message()`, `send_choice_message()`, `send_contact_info_message()`, `send_list_message()`, `send_location_message()`, `send_media_message()`, `send_template_message()`<br>Or `send()` with `app_id`, `message` (dict or `SendMessageRequestBodyDict`), and either `contact_id` or `recipient_identities` |
122+
| `get()` with `GetConversationMessageRequest` | `get()` with `message_id: str` parameter |
123+
| `delete()` with `DeleteConversationMessageRequest` | `delete()` with `message_id: str` parameter |
124+
| `list()` with `ListConversationMessagesRequest` | In Progress |
125+
|| **New in V2:** `update()` with `message_id`, `metadata`, and optional `messages_source`|
126+
127+
<br>
128+
96129
### [`SMS`](https://github.com/sinch/sinch-sdk-python/tree/main/sinch/domains/sms)
97130

98131
#### Replacement models
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
Sinch Python Snippet
3+
4+
TODO: Update links when v2 is released.
5+
This snippet is available at https://github.com/sinch/sinch-sdk-python/blob/v2.0/docs/snippets/
6+
"""
7+
8+
import os
9+
from dotenv import load_dotenv
10+
from sinch import SinchClient
11+
12+
load_dotenv()
13+
14+
sinch_client = SinchClient(
15+
project_id=os.environ.get("SINCH_PROJECT_ID") or "MY_PROJECT_ID",
16+
key_id=os.environ.get("SINCH_KEY_ID") or "MY_KEY_ID",
17+
key_secret=os.environ.get("SINCH_KEY_SECRET") or "MY_KEY_SECRET",
18+
conversation_region=os.environ.get("SINCH_CONVERSATION_REGION") or "MY_CONVERSATION_REGION"
19+
)
20+
21+
# The ID of the Conversation App to send the message from
22+
app_id = "CONVERSATION_APP_ID"
23+
# The phone number of the recipient in E.164 format (e.g. +46701234567)
24+
recipient_identities = [
25+
{
26+
"channel": "RCS",
27+
"identity": "RECIPIENT_PHONE_NUMBER"
28+
}
29+
]
30+
31+
response = sinch_client.conversation.messages.send(
32+
app_id=app_id,
33+
message={
34+
"text_message": {
35+
"text": "[Python SDK: Conversation Message] Sample text message"
36+
}
37+
},
38+
recipient_identities=recipient_identities
39+
)
40+
41+
print(f"Successfully sent message.\n{response}")
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""
2+
Sinch Python Snippet
3+
4+
TODO: Update links when v2 is released.
5+
This snippet is available at https://github.com/sinch/sinch-sdk-python/blob/v2.0/docs/snippets/
6+
"""
7+
8+
import os
9+
from dotenv import load_dotenv
10+
from sinch import SinchClient
11+
12+
load_dotenv()
13+
14+
sinch_client = SinchClient(
15+
project_id=os.environ.get("SINCH_PROJECT_ID") or "MY_PROJECT_ID",
16+
key_id=os.environ.get("SINCH_KEY_ID") or "MY_KEY_ID",
17+
key_secret=os.environ.get("SINCH_KEY_SECRET") or "MY_KEY_SECRET",
18+
conversation_region=os.environ.get("SINCH_CONVERSATION_REGION") or "MY_CONVERSATION_REGION"
19+
)
20+
21+
# The ID of the Conversation App to send the message from
22+
app_id = "CONVERSATION_APP_ID"
23+
# The phone number of the recipient in E.164 format (e.g. +46701234567)
24+
recipient_identities = [
25+
{
26+
"channel": "RCS",
27+
"identity": "RECIPIENT_PHONE_NUMBER"
28+
}
29+
]
30+
31+
card_message = {
32+
"title": "Card title",
33+
"description": "Optional card description",
34+
"choices": [
35+
{"text_message": {"text": "Yes"}, "postback_data": "yes"},
36+
{"text_message": {"text": "No"}, "postback_data": "no"},
37+
]
38+
}
39+
40+
response = sinch_client.conversation.messages.send_card_message(
41+
app_id=app_id,
42+
card_message=card_message,
43+
recipient_identities=recipient_identities
44+
)
45+
46+
print(f"Successfully sent card message.\n{response}")
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
Sinch Python Snippet
3+
4+
TODO: Update links when v2 is released.
5+
This snippet is available at https://github.com/sinch/sinch-sdk-python/blob/v2.0/docs/snippets/
6+
"""
7+
8+
import os
9+
from dotenv import load_dotenv
10+
from sinch import SinchClient
11+
12+
load_dotenv()
13+
14+
sinch_client = SinchClient(
15+
project_id=os.environ.get("SINCH_PROJECT_ID") or "MY_PROJECT_ID",
16+
key_id=os.environ.get("SINCH_KEY_ID") or "MY_KEY_ID",
17+
key_secret=os.environ.get("SINCH_KEY_SECRET") or "MY_KEY_SECRET",
18+
conversation_region=os.environ.get("SINCH_CONVERSATION_REGION") or "MY_CONVERSATION_REGION"
19+
)
20+
21+
# The ID of the Conversation App to send the message from
22+
app_id = "CONVERSATION_APP_ID"
23+
# The phone number of the recipient in E.164 format (e.g. +46701234567)
24+
recipient_identities = [
25+
{
26+
"channel": "RCS",
27+
"identity": "RECIPIENT_PHONE_NUMBER"
28+
}
29+
]
30+
31+
carousel_message = {
32+
"cards": [
33+
{
34+
"title": "Card 1",
35+
"description": "First card description",
36+
"choices": [{"text_message": {"text": "Option 1"}}],
37+
},
38+
{
39+
"title": "Card 2",
40+
"description": "Second card description",
41+
"choices": [{"url_message": {"title": "Link", "url": "https://example.com"}}],
42+
},
43+
],
44+
}
45+
46+
response = sinch_client.conversation.messages.send_carousel_message(
47+
app_id=app_id,
48+
carousel_message=carousel_message,
49+
recipient_identities=recipient_identities
50+
)
51+
52+
print(f"Successfully sent carousel message.\n{response}")
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
Sinch Python Snippet
3+
4+
TODO: Update links when v2 is released.
5+
This snippet is available at https://github.com/sinch/sinch-sdk-python/blob/v2.0/docs/snippets/
6+
"""
7+
8+
import os
9+
from dotenv import load_dotenv
10+
from sinch import SinchClient
11+
12+
load_dotenv()
13+
14+
sinch_client = SinchClient(
15+
project_id=os.environ.get("SINCH_PROJECT_ID") or "MY_PROJECT_ID",
16+
key_id=os.environ.get("SINCH_KEY_ID") or "MY_KEY_ID",
17+
key_secret=os.environ.get("SINCH_KEY_SECRET") or "MY_KEY_SECRET",
18+
conversation_region=os.environ.get("SINCH_CONVERSATION_REGION") or "MY_CONVERSATION_REGION"
19+
)
20+
21+
# The ID of the Conversation App to send the message from
22+
app_id = "CONVERSATION_APP_ID"
23+
# The phone number of the recipient in E.164 format (e.g. +46701234567)
24+
recipient_identities = [
25+
{
26+
"channel": "RCS",
27+
"identity": "RECIPIENT_PHONE_NUMBER"
28+
}
29+
]
30+
31+
choice_message = {
32+
"text_message": {"text": "Choose an option:"},
33+
"choices": [
34+
{"text_message": {"text": "Option A"}, "postback_data": "option_a"},
35+
{"text_message": {"text": "Option B"}, "postback_data": "option_b"},
36+
],
37+
}
38+
39+
response = sinch_client.conversation.messages.send_choice_message(
40+
app_id=app_id,
41+
choice_message=choice_message,
42+
recipient_identities=recipient_identities
43+
)
44+
45+
print(f"Successfully sent choice message.\n{response}")
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Sinch Python Snippet
3+
4+
TODO: Update links when v2 is released.
5+
This snippet is available at https://github.com/sinch/sinch-sdk-python/blob/v2.0/docs/snippets/
6+
"""
7+
8+
import os
9+
from dotenv import load_dotenv
10+
from sinch import SinchClient
11+
12+
load_dotenv()
13+
14+
sinch_client = SinchClient(
15+
project_id=os.environ.get("SINCH_PROJECT_ID") or "MY_PROJECT_ID",
16+
key_id=os.environ.get("SINCH_KEY_ID") or "MY_KEY_ID",
17+
key_secret=os.environ.get("SINCH_KEY_SECRET") or "MY_KEY_SECRET",
18+
conversation_region=os.environ.get("SINCH_CONVERSATION_REGION") or "MY_CONVERSATION_REGION"
19+
)
20+
21+
# The ID of the Conversation App to send the message from
22+
app_id = "CONVERSATION_APP_ID"
23+
# The phone number of the recipient in E.164 format (e.g. +46701234567)
24+
recipient_identities = [
25+
{
26+
"channel": "RCS",
27+
"identity": "RECIPIENT_PHONE_NUMBER"
28+
}
29+
]
30+
31+
contact_info_message = {
32+
"name": {"full_name": "John Doe"},
33+
"phone_numbers": [{"phone_number": "+1234567890"}],
34+
}
35+
36+
response = sinch_client.conversation.messages.send_contact_info_message(
37+
app_id=app_id,
38+
contact_info_message=contact_info_message,
39+
recipient_identities=recipient_identities
40+
)
41+
42+
print(f"Successfully sent contact info message.\n{response}")
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Sinch Python Snippet
3+
4+
TODO: Update links when v2 is released.
5+
This snippet is available at https://github.com/sinch/sinch-sdk-python/blob/v2.0/docs/snippets/
6+
"""
7+
8+
import os
9+
from dotenv import load_dotenv
10+
from sinch import SinchClient
11+
12+
load_dotenv()
13+
14+
sinch_client = SinchClient(
15+
project_id=os.environ.get("SINCH_PROJECT_ID") or "MY_PROJECT_ID",
16+
key_id=os.environ.get("SINCH_KEY_ID") or "MY_KEY_ID",
17+
key_secret=os.environ.get("SINCH_KEY_SECRET") or "MY_KEY_SECRET",
18+
conversation_region=os.environ.get("SINCH_CONVERSATION_REGION") or "MY_CONVERSATION_REGION"
19+
)
20+
21+
# The ID of the Conversation App to send the message from
22+
app_id = "CONVERSATION_APP_ID"
23+
# The phone number of the recipient in E.164 format (e.g. +46701234567)
24+
recipient_identities = [
25+
{
26+
"channel": "RCS",
27+
"identity": "RECIPIENT_PHONE_NUMBER"
28+
}
29+
]
30+
31+
list_message = {
32+
"title": "Choose an option",
33+
"description": "Select from the list below",
34+
"sections": [
35+
{
36+
"title": "Section 1",
37+
"items": [
38+
{"choice": {"title": "Option A", "postback_data": "option_a"}},
39+
{"choice": {"title": "Option B", "postback_data": "option_b"}},
40+
],
41+
},
42+
],
43+
}
44+
45+
response = sinch_client.conversation.messages.send_list_message(
46+
app_id=app_id,
47+
list_message=list_message,
48+
recipient_identities=recipient_identities
49+
)
50+
51+
print(f"Successfully sent list message.\n{response}")
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Sinch Python Snippet
3+
4+
TODO: Update links when v2 is released.
5+
This snippet is available at https://github.com/sinch/sinch-sdk-python/blob/v2.0/docs/snippets/
6+
"""
7+
8+
import os
9+
from dotenv import load_dotenv
10+
from sinch import SinchClient
11+
12+
load_dotenv()
13+
14+
sinch_client = SinchClient(
15+
project_id=os.environ.get("SINCH_PROJECT_ID") or "MY_PROJECT_ID",
16+
key_id=os.environ.get("SINCH_KEY_ID") or "MY_KEY_ID",
17+
key_secret=os.environ.get("SINCH_KEY_SECRET") or "MY_KEY_SECRET",
18+
conversation_region=os.environ.get("SINCH_CONVERSATION_REGION") or "MY_CONVERSATION_REGION"
19+
)
20+
21+
# The ID of the Conversation App to send the message from
22+
app_id = "CONVERSATION_APP_ID"
23+
# The phone number of the recipient in E.164 format (e.g. +46701234567)
24+
recipient_identities = [
25+
{
26+
"channel": "RCS",
27+
"identity": "RECIPIENT_PHONE_NUMBER"
28+
}
29+
]
30+
31+
location_message = {
32+
"title": "Our office",
33+
"coordinates": {"latitude": 59.3293, "longitude": 18.0686},
34+
}
35+
36+
response = sinch_client.conversation.messages.send_location_message(
37+
app_id=app_id,
38+
location_message=location_message,
39+
recipient_identities=recipient_identities
40+
)
41+
42+
print(f"Successfully sent location message.\n{response}")

0 commit comments

Comments
 (0)