Skip to content

Commit a2247a4

Browse files
fix: added ListMessagesByChannelIdentityAuto.cs and SendSmsTextMessage.cs snippets
1 parent 92d3470 commit a2247a4

6 files changed

Lines changed: 171 additions & 5 deletions

File tree

examples/snippets/Snippets.sln

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendOrderDetailsPaymentButt
129129
EndProject
130130
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ListMessagesByChannelIdentity", "conversation\messages\ListMessagesByChannelIdentity\ListMessagesByChannelIdentity.csproj", "{2FB7178D-65CA-47E4-A09E-E26987408B8A}"
131131
EndProject
132+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ListMessagesByChannelIdentityAuto", "conversation\messages\ListMessagesByChannelIdentityAuto\ListMessagesByChannelIdentityAuto.csproj", "{FA0DBEC6-BEAA-4293-946A-99873ACE4A46}"
133+
EndProject
134+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendSmsTextMessage", "conversation\messages\SendSmsTextMessage\SendSmsTextMessage.csproj", "{A3447A99-9256-4F6F-95FD-1ECF3EBEA6FD}"
135+
EndProject
132136
Global
133137
GlobalSection(SolutionConfigurationPlatforms) = preSolution
134138
Debug|Any CPU = Debug|Any CPU
@@ -715,6 +719,30 @@ Global
715719
{2FB7178D-65CA-47E4-A09E-E26987408B8A}.Release|x64.Build.0 = Release|Any CPU
716720
{2FB7178D-65CA-47E4-A09E-E26987408B8A}.Release|x86.ActiveCfg = Release|Any CPU
717721
{2FB7178D-65CA-47E4-A09E-E26987408B8A}.Release|x86.Build.0 = Release|Any CPU
722+
{FA0DBEC6-BEAA-4293-946A-99873ACE4A46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
723+
{FA0DBEC6-BEAA-4293-946A-99873ACE4A46}.Debug|Any CPU.Build.0 = Debug|Any CPU
724+
{FA0DBEC6-BEAA-4293-946A-99873ACE4A46}.Debug|x64.ActiveCfg = Debug|Any CPU
725+
{FA0DBEC6-BEAA-4293-946A-99873ACE4A46}.Debug|x64.Build.0 = Debug|Any CPU
726+
{FA0DBEC6-BEAA-4293-946A-99873ACE4A46}.Debug|x86.ActiveCfg = Debug|Any CPU
727+
{FA0DBEC6-BEAA-4293-946A-99873ACE4A46}.Debug|x86.Build.0 = Debug|Any CPU
728+
{FA0DBEC6-BEAA-4293-946A-99873ACE4A46}.Release|Any CPU.ActiveCfg = Release|Any CPU
729+
{FA0DBEC6-BEAA-4293-946A-99873ACE4A46}.Release|Any CPU.Build.0 = Release|Any CPU
730+
{FA0DBEC6-BEAA-4293-946A-99873ACE4A46}.Release|x64.ActiveCfg = Release|Any CPU
731+
{FA0DBEC6-BEAA-4293-946A-99873ACE4A46}.Release|x64.Build.0 = Release|Any CPU
732+
{FA0DBEC6-BEAA-4293-946A-99873ACE4A46}.Release|x86.ActiveCfg = Release|Any CPU
733+
{FA0DBEC6-BEAA-4293-946A-99873ACE4A46}.Release|x86.Build.0 = Release|Any CPU
734+
{A3447A99-9256-4F6F-95FD-1ECF3EBEA6FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
735+
{A3447A99-9256-4F6F-95FD-1ECF3EBEA6FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
736+
{A3447A99-9256-4F6F-95FD-1ECF3EBEA6FD}.Debug|x64.ActiveCfg = Debug|Any CPU
737+
{A3447A99-9256-4F6F-95FD-1ECF3EBEA6FD}.Debug|x64.Build.0 = Debug|Any CPU
738+
{A3447A99-9256-4F6F-95FD-1ECF3EBEA6FD}.Debug|x86.ActiveCfg = Debug|Any CPU
739+
{A3447A99-9256-4F6F-95FD-1ECF3EBEA6FD}.Debug|x86.Build.0 = Debug|Any CPU
740+
{A3447A99-9256-4F6F-95FD-1ECF3EBEA6FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
741+
{A3447A99-9256-4F6F-95FD-1ECF3EBEA6FD}.Release|Any CPU.Build.0 = Release|Any CPU
742+
{A3447A99-9256-4F6F-95FD-1ECF3EBEA6FD}.Release|x64.ActiveCfg = Release|Any CPU
743+
{A3447A99-9256-4F6F-95FD-1ECF3EBEA6FD}.Release|x64.Build.0 = Release|Any CPU
744+
{A3447A99-9256-4F6F-95FD-1ECF3EBEA6FD}.Release|x86.ActiveCfg = Release|Any CPU
745+
{A3447A99-9256-4F6F-95FD-1ECF3EBEA6FD}.Release|x86.Build.0 = Release|Any CPU
718746
EndGlobalSection
719747
GlobalSection(SolutionProperties) = preSolution
720748
HideSolutionNode = FALSE
@@ -779,6 +807,8 @@ Global
779807
{2750A256-190C-4A18-89FA-5349BE6E5BDB} = {EAC3562A-E072-404F-806B-BDBD7F8DB06C}
780808
{30C715C1-731F-408E-BD6D-31A1C120BF30} = {D14691D8-5D33-4332-8CDB-D0C6A4FAFF20}
781809
{2FB7178D-65CA-47E4-A09E-E26987408B8A} = {D14691D8-5D33-4332-8CDB-D0C6A4FAFF20}
810+
{FA0DBEC6-BEAA-4293-946A-99873ACE4A46} = {D14691D8-5D33-4332-8CDB-D0C6A4FAFF20}
811+
{A3447A99-9256-4F6F-95FD-1ECF3EBEA6FD} = {D14691D8-5D33-4332-8CDB-D0C6A4FAFF20}
782812
EndGlobalSection
783813
GlobalSection(ExtensibilityGlobals) = postSolution
784814
SolutionGuid = {4081DB0B-E6B8-47EB-A4AF-C9C20DAB9EE2}

examples/snippets/conversation/messages/ListMessagesByChannelIdentity/ListMessagesByChannelIdentity.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111

1212
// The ID of the Conversation Application
1313
const string conversationApplicationId = "CONVERSATION_APP_ID";
14-
15-
// Channel identity to filter by
16-
const string channelIdentity = "CHANNEL_IDENTITY";
14+
// The channel identities to list messages for (e.g. recipient phone numbers for SMS)
15+
List<string> channelIdentities = ["CHANNEL_IDENTITY1", "CHANNEL_IDENTITY2"];
1716

1817
var client = new SinchClient(new SinchClientConfiguration
1918
{
@@ -32,10 +31,12 @@
3231
var request = new ListMessagesByChannelIdentityRequest
3332
{
3433
AppId = conversationApplicationId,
35-
ChannelIdentities = new List<string> { channelIdentity }
34+
Channel = ConversationChannel.Sms,
35+
ChannelIdentities = channelIdentities,
36+
MessagesSource = MessageSource.ConversationSource
3637
};
3738

38-
Console.WriteLine($"Listing messages by channel identity for application '{conversationApplicationId}'");
39+
Console.WriteLine($"Listing SMS messages for '{string.Join(",", channelIdentities)}' in application '{conversationApplicationId}'");
3940

4041
var response = await client.Conversation.Messages.ListMessagesByChannelIdentity(request);
4142

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Sinch;
2+
using Sinch.Conversation;
3+
using Sinch.Conversation.Messages.List;
4+
using Sinch.Core;
5+
using Sinch.Snippets.Shared;
6+
7+
var projectId = ConfigurationHelper.GetProjectId() ?? "MY_PROJECT_ID";
8+
var keyId = ConfigurationHelper.GetKeyId() ?? "MY_KEY_ID";
9+
var keySecret = ConfigurationHelper.GetKeySecret() ?? "MY_KEY_SECRET";
10+
var conversationRegion = ConfigurationHelper.GetConversationRegion() ?? "MY_CONVERSATION_REGION";
11+
12+
// The ID of the Conversation Application
13+
const string conversationApplicationId = "CONVERSATION_APP_ID";
14+
// The channel identities to list messages for (e.g. recipient phone numbers for SMS)
15+
List<string> channelIdentities = ["CHANNEL_IDENTITY1", "CHANNEL_IDENTITY2"];
16+
17+
var client = new SinchClient(new SinchClientConfiguration
18+
{
19+
SinchUnifiedCredentials = new SinchUnifiedCredentials
20+
{
21+
ProjectId = projectId,
22+
KeyId = keyId,
23+
KeySecret = keySecret
24+
},
25+
ConversationConfiguration = new SinchConversationConfiguration
26+
{
27+
ConversationRegion = new ConversationRegion(conversationRegion)
28+
}
29+
});
30+
31+
var request = new ListMessagesByChannelIdentityRequest
32+
{
33+
AppId = conversationApplicationId,
34+
Channel = ConversationChannel.Sms,
35+
ChannelIdentities = channelIdentities,
36+
MessagesSource = MessageSource.ConversationSource
37+
};
38+
39+
Console.WriteLine($"Listing last SMS message per identity in application '{conversationApplicationId}'");
40+
41+
await foreach (var message in client.Conversation.Messages.ListMessagesByChannelIdentityAuto(request))
42+
{
43+
Console.WriteLine(message.ToPrettyString());
44+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\..\..\..\..\src\Sinch\Sinch.csproj" />
12+
<ProjectReference Include="..\..\..\Shared\SnippetsConfig.Shared.csproj" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using Sinch;
2+
using Sinch.Conversation;
3+
using Sinch.Conversation.Common;
4+
using Sinch.Conversation.Messages.Message;
5+
using Sinch.Conversation.Messages.Send;
6+
using Sinch.Snippets.Shared;
7+
8+
var projectId = ConfigurationHelper.GetProjectId() ?? "MY_PROJECT_ID";
9+
var keyId = ConfigurationHelper.GetKeyId() ?? "MY_KEY_ID";
10+
var keySecret = ConfigurationHelper.GetKeySecret() ?? "MY_KEY_SECRET";
11+
var conversationRegion = ConfigurationHelper.GetConversationRegion() ?? "MY_CONVERSATION_REGION";
12+
var sinchVirtualPhoneNumber = ConfigurationHelper.GetPhoneNumber() ?? "SINCH_VIRTUAL_PHONE_NUMBER";
13+
14+
// The ID of the Conversation Application
15+
const string conversationApplicationId = "CONVERSATION_APP_ID";
16+
// The recipient phone number in E.164 format (e.g. +14155552671)
17+
const string recipientPhoneNumber = "RECIPIENT_PHONE_NUMBER";
18+
19+
var client = new SinchClient(new SinchClientConfiguration
20+
{
21+
SinchUnifiedCredentials = new SinchUnifiedCredentials
22+
{
23+
ProjectId = projectId,
24+
KeyId = keyId,
25+
KeySecret = keySecret
26+
},
27+
ConversationConfiguration = new SinchConversationConfiguration
28+
{
29+
ConversationRegion = new ConversationRegion(conversationRegion)
30+
}
31+
});
32+
33+
var request = new SendMessageRequest
34+
{
35+
AppId = conversationApplicationId,
36+
Recipient = new Identified
37+
{
38+
IdentifiedBy = new IdentifiedBy
39+
{
40+
ChannelIdentities =
41+
[
42+
new ChannelIdentity
43+
{
44+
Channel = ConversationChannel.Sms,
45+
Identity = recipientPhoneNumber
46+
}
47+
]
48+
}
49+
},
50+
ChannelProperties = new Dictionary<string, string>
51+
{
52+
{ "SMS_SENDER", sinchVirtualPhoneNumber }
53+
},
54+
Message = new AppMessage(new TextMessage("Hello from the Sinch .NET SDK!"))
55+
};
56+
57+
Console.WriteLine($"Sending SMS to '{recipientPhoneNumber}'...");
58+
59+
var response = await client.Conversation.Messages.Send(request);
60+
61+
Console.WriteLine($"Message sent! Message ID: {response.MessageId}");
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\..\..\..\..\src\Sinch\Sinch.csproj" />
12+
<ProjectReference Include="..\..\..\Shared\SnippetsConfig.Shared.csproj" />
13+
</ItemGroup>
14+
15+
</Project>

0 commit comments

Comments
 (0)