Skip to content

Commit 689b6a8

Browse files
dcesljasdcesljas
authored andcommitted
Added OMNI API support
1 parent fa7c17b commit 689b6a8

File tree

126 files changed

+2428
-307
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+2428
-307
lines changed

InfobipClient/InfobipClientExamples/ExampleRunner.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ static void Main(string[] args)
3131
//new SingleTextualSmsExample().RunExampleAsync().Wait();
3232

3333
//new SmsPreviewExample().RunExampleAsync().Wait();
34+
35+
//new AdvancedOmniMessageExample().RunExampleAsync().Wait();
3436
}
3537
}
3638
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Infobip.Api.Model.Omni;
7+
using Infobip.Api.Model.Omni.Send;
8+
9+
10+
namespace Infobip.Api.Client.Examples
11+
{
12+
class AdvancedOmniMessageExample : Example
13+
{
14+
public override async Task RunExampleAsync()
15+
{
16+
string bulkId = await AdvancedOmniAsync();
17+
18+
System.Threading.Thread.Sleep(2000);
19+
20+
await GetOmniReportAsync(bulkId);
21+
}
22+
23+
private static async Task<string> AdvancedOmniAsync()
24+
{
25+
Console.WriteLine("-------------------------------");
26+
Console.WriteLine("Sending Advance OMNI message...");
27+
28+
SendAdvancedOmniMessage omniClient = new SendAdvancedOmniMessage(BASIC_AUTH_CONFIGURATION);
29+
30+
Destination destination = new Destination
31+
{
32+
To = new To
33+
{
34+
PhoneNumber = TO
35+
}
36+
};
37+
38+
SmsData smsData = new SmsData
39+
{
40+
Text = "Artık Ulusal Dil Tanımlayıcısı ile Türkçe karakterli smslerinizi rahatlıkla iletebilirsiniz.",
41+
Language = new Language { LanguageCode = "TR" },
42+
Transliteration = "TURKISH"
43+
};
44+
45+
ViberData viberData = new ViberData
46+
{
47+
Text = "Luke, I'm your father!"
48+
};
49+
50+
OmniAdvancedRequest request = new OmniAdvancedRequest
51+
{
52+
Destinations = new List<Destination>(1) { destination },
53+
ScenarioKey = "6EDEA8BF17983A97C42BCA702F0A673D", // Your-Scenario-Key
54+
Sms = smsData,
55+
Viber = viberData
56+
};
57+
58+
OmniResponse omniResponse = await omniClient.ExecuteAsync(request);
59+
Console.WriteLine("-------------------------------");
60+
Console.WriteLine("Bulk ID: " + omniResponse.BulkId);
61+
Console.WriteLine("-------------------------------");
62+
foreach (OmniResponseDetails sentMessageInfo in omniResponse.Messages)
63+
{
64+
Console.WriteLine("Message ID: " + sentMessageInfo.MessageId);
65+
Console.WriteLine("Message status: " + sentMessageInfo.Status.Name);
66+
Console.WriteLine("-------------------------------");
67+
}
68+
69+
return omniResponse.BulkId;
70+
}
71+
}
72+
}

InfobipClient/InfobipClientExamples/Examples/AdvancedSmsSchedulingExample.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Infobip.Api.Model.Sms.Mt.Bulks.Status;
44
using Infobip.Api.Model.Sms.Mt.Send;
55
using Infobip.Api.Model.Sms.Mt.Send.Textual;
6+
using Infobip.Api.Config;
67
using System;
78
using System.Collections.Generic;
89
using System.Threading.Tasks;
@@ -94,7 +95,7 @@ private static async Task<SMSResponse> SendScheduledMessageAsync()
9495
From = FROM,
9596
Destinations = new List<Destination>(1) { destination },
9697
Text = "Advanced scheduled message example",
97-
SendAt = sendAt
98+
SendAt = new FormattedDate(sendAt)
9899
};
99100

100101
SMSAdvancedTextualRequest request = new SMSAdvancedTextualRequest
@@ -115,7 +116,7 @@ private static async Task<BulkResponse> GetBulkAsync(string bulkId)
115116
private static async void RescheduleMessageAsync(String bulkId)
116117
{
117118
DateTimeOffset sendAt = NOW.AddMinutes(30);
118-
BulkRequest rescheduleRequest = new BulkRequest{ SendAt = sendAt };
119+
BulkRequest rescheduleRequest = new BulkRequest{ SendAt = new FormattedDate(sendAt) };
119120
RescheduleBulkExecuteContext context = new RescheduleBulkExecuteContext { BulkId = bulkId };
120121

121122
await new RescheduleBulk(BASIC_AUTH_CONFIGURATION).ExecuteAsync(context, rescheduleRequest);

InfobipClient/InfobipClientExamples/Examples/Example.cs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Infobip.Api.Config;
22
using Infobip.Api.Model.Sms.Mt.Reports;
3+
using Infobip.Api.Model.Omni.Reports;
34
using System;
45
using System.Collections.Generic;
56
using System.Linq;
@@ -16,7 +17,7 @@ abstract class Example
1617
protected static readonly BasicAuthConfiguration BASIC_AUTH_CONFIGURATION = new BasicAuthConfiguration(BASE_URL, USERNAME, PASSWORD);
1718

1819
protected static readonly string FROM = "InfoSMS";
19-
protected static readonly string TO = "PHONE";
20+
protected static readonly string TO = "451965782149";
2021
protected static readonly List<string> TO_LIST = new List<string>(1) { "PHONE" };
2122
protected static readonly string MESSAGE_TEXT = "This is an example message sent via C# example lib.";
2223

@@ -53,11 +54,44 @@ protected static void PrintFirstReportDetails(SMSReportResponse response)
5354
SMSReport report = response.Results[0];
5455
Console.WriteLine("-------------------------------");
5556
Console.WriteLine("Message ID: " + report.MessageId);
56-
Console.WriteLine("Sent at: " + report.SentAt.ToLocalTime());
57+
Console.WriteLine("Sent at: " + report.SentAt);
5758
Console.WriteLine("Receiver: " + report.To);
5859
Console.WriteLine("Status: " + report.Status.Name);
5960
Console.WriteLine("Price: " + report.Price.PricePerMessage + " " + report.Price.Currency);
6061
Console.WriteLine("-------------------------------");
6162
}
63+
64+
protected static async Task<OMNIReportsResponse> GetOmniReportAsync(string bulkId)
65+
{
66+
Console.WriteLine("-------------------------------");
67+
Console.WriteLine("Fetching reports...");
68+
69+
GetOMNIReports omniReportsClient = new GetOMNIReports(BASIC_AUTH_CONFIGURATION);
70+
GetOMNIReportsExecuteContext context = new GetOMNIReportsExecuteContext
71+
{
72+
BulkId = bulkId
73+
};
74+
OMNIReportsResponse response = await omniReportsClient.ExecuteAsync(context);
75+
76+
if (!response.Results.Any())
77+
{
78+
Console.WriteLine("No report to fetch.");
79+
return new OMNIReportsResponse();
80+
}
81+
Console.WriteLine("Fetching report complete.");
82+
83+
foreach (OMNIReport report in response.Results)
84+
{
85+
Console.WriteLine("-------------------------------");
86+
Console.WriteLine("Message ID: " + report.MessageId);
87+
Console.WriteLine("Sent at: " + report.SentAt);
88+
Console.WriteLine("Channel: " + report.Channel);
89+
Console.WriteLine("Status: " + report.Status.Name);
90+
Console.WriteLine("Price: " + report.Price.PricePerMessage + " " + report.Price.Currency);
91+
Console.WriteLine("-------------------------------");
92+
}
93+
94+
return response;
95+
}
6296
}
6397
}

InfobipClient/InfobipClientExamples/Examples/GetInboxLogsExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public override async Task RunExampleAsync()
1313
GetReceivedSmsLogsExecuteContext context = new GetReceivedSmsLogsExecuteContext()
1414
{
1515
To = null,
16+
Limit = 10,
1617
ReceivedSince = null,
1718
ReceivedUntil = null,
18-
Limit = 10,
1919
Keyword = null
2020
};
2121
MOLogsResponse response = await client.ExecuteAsync(context);

InfobipClient/InfobipClientExamples/Examples/PullInboxDeliveryReportsExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public override async Task RunExampleAsync()
1414
GetReceivedSmsLogsExecuteContext context = new GetReceivedSmsLogsExecuteContext
1515
{
1616
To = null,
17+
Limit = 10,
1718
ReceivedSince = null,
1819
ReceivedUntil = null,
19-
Limit = 10,
2020
Keyword = null
2121
};
2222

InfobipClient/InfobipClientExamples/InfobipClientExamples.csproj

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434
<None Include="App.config" />
3535
<None Include="packages.config" />
3636
</ItemGroup>
37-
<ItemGroup>
38-
<ProjectReference Include="..\InfobipClientLib\InfobipClientLib.csproj">
39-
<Project>{95264b1b-6efa-4791-a75f-481464fd5cd3}</Project>
40-
<Name>InfobipClientLib</Name>
41-
</ProjectReference>
42-
</ItemGroup>
4337
<ItemGroup>
4438
<Compile Include="ExampleRunner.cs" />
4539
<Compile Include="Examples\AdvancedSmsDeliveryTimeWindowExample.cs" />
@@ -49,6 +43,7 @@
4943
<Compile Include="Examples\AdvancedSmsNotifyExample.cs" />
5044
<Compile Include="Examples\AdvancedSmsSchedulingExample.cs" />
5145
<Compile Include="Examples\AdvancedSmsTrackingExample.cs" />
46+
<Compile Include="Examples\AdvancedOmniMessageExample.cs" />
5247
<Compile Include="Examples\Example.cs" />
5348
<Compile Include="Examples\GetAccountBalanceExample.cs" />
5449
<Compile Include="Examples\GetInboxLogsExample.cs" />
@@ -63,8 +58,15 @@
6358
<Compile Include="Examples\SmsPreviewExample.cs" />
6459
</ItemGroup>
6560
<ItemGroup>
66-
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
67-
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
61+
<ProjectReference Include="..\InfobipClientLib\InfobipClientLib.csproj">
62+
<Project>{95264b1b-6efa-4791-a75f-481464fd5cd3}</Project>
63+
<Name>InfobipClientLib</Name>
64+
</ProjectReference>
65+
</ItemGroup>
66+
<ItemGroup>
67+
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
68+
<SpecificVersion>False</SpecificVersion>
69+
<HintPath>..\..\..\..\..\.nuget\packages\newtonsoft.json\10.0.3\lib\portable-net45+win8+wp8+wpa81\Newtonsoft.Json.dll</HintPath>
6870
</Reference>
6971
</ItemGroup>
7072
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
55
</startup>
6-
</configuration>
6+
</configuration>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using Infobip.Api.Config;
2+
using Infobip.Api.Model.Exception;
3+
using Newtonsoft.Json;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Collections.Specialized;
7+
using System.Net.Http;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using System.Web;
11+
using Infobip.Api.Model.Omni.Campaign;
12+
13+
namespace Infobip.Api.Client
14+
{
15+
/// <summary>
16+
/// This is a generated class and is not intended for modification!
17+
/// </summary>
18+
public class AddDestination
19+
{
20+
private static string path = "/omni/2/campaigns/{campaignKey}/destinations";
21+
22+
private Config.Configuration configuration;
23+
24+
private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
25+
{
26+
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
27+
DateParseHandling = DateParseHandling.DateTimeOffset,
28+
Converters = new List<JsonConverter>(1) { new FormattedDateConverter() }
29+
};
30+
31+
public AddDestination(Config.Configuration configuration)
32+
{
33+
this.configuration = configuration;
34+
}
35+
36+
public async Task<Campaign> ExecuteAsync(string campaignKey, Destinations bodyObject)
37+
{
38+
using (var client = HttpClientProvider.GetHttpClient(configuration))
39+
{
40+
string endpoint = path;
41+
endpoint = endpoint.Replace("{campaignKey}", HttpUtility.UrlEncode(campaignKey));
42+
43+
string requestJson = JsonConvert.SerializeObject(bodyObject, Settings);
44+
HttpContent content = new StringContent(requestJson, Encoding.UTF8, "application/json");
45+
46+
var response = await client.PutAsync(endpoint, content);
47+
string contents = await response.Content.ReadAsStringAsync();
48+
49+
if (response.IsSuccessStatusCode)
50+
{
51+
return JsonConvert.DeserializeObject<Campaign>(contents, Settings);
52+
}
53+
else
54+
{
55+
throw new InfobipApiException(
56+
response.StatusCode,
57+
JsonConvert.DeserializeObject<ApiErrorResponse>(contents, Settings)
58+
);
59+
}
60+
}
61+
}
62+
63+
}
64+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Infobip.Api.Config;
2+
using Infobip.Api.Model.Exception;
3+
using Newtonsoft.Json;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Collections.Specialized;
7+
using System.Net.Http;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using System.Web;
11+
using Infobip.Api.Model.Omni.Scenarios;
12+
namespace Infobip.Api.Client
13+
{
14+
/// <summary>
15+
/// This is a generated class and is not intended for modification!
16+
/// </summary>
17+
public class CreateScenario
18+
{
19+
private static string path = "/omni/1/scenarios";
20+
21+
private Config.Configuration configuration;
22+
23+
private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
24+
{
25+
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
26+
DateParseHandling = DateParseHandling.DateTimeOffset,
27+
Converters = new List<JsonConverter>(1) { new FormattedDateConverter() }
28+
};
29+
30+
public CreateScenario(Config.Configuration configuration)
31+
{
32+
this.configuration = configuration;
33+
}
34+
35+
public async Task<Scenario> ExecuteAsync(Scenario bodyObject)
36+
{
37+
using (var client = HttpClientProvider.GetHttpClient(configuration))
38+
{
39+
string endpoint = path;
40+
41+
string requestJson = JsonConvert.SerializeObject(bodyObject, Settings);
42+
HttpContent content = new StringContent(requestJson, Encoding.UTF8, "application/json");
43+
44+
var response = await client.PostAsync(endpoint, content);
45+
string contents = await response.Content.ReadAsStringAsync();
46+
47+
if (response.IsSuccessStatusCode)
48+
{
49+
return JsonConvert.DeserializeObject<Scenario>(contents, Settings);
50+
}
51+
else
52+
{
53+
throw new InfobipApiException(
54+
response.StatusCode,
55+
JsonConvert.DeserializeObject<ApiErrorResponse>(contents, Settings)
56+
);
57+
}
58+
}
59+
}
60+
61+
}
62+
}

0 commit comments

Comments
 (0)