Skip to content

Commit 34fc2a5

Browse files
committed
mod insight model
1 parent 60d5975 commit 34fc2a5

10 files changed

Lines changed: 191 additions & 81 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ but I recommend that you should use a LineMessagingClient class instead of each
6868
|---|---|---|
6969
|[Get number of message deliveries](https://developers.line.biz/en/reference/messaging-api/#get-number-of-delivery-messages)|GetNumberOfMessageDeliveriesAsync|✔|
7070
|[Get number of followers](https://developers.line.biz/en/reference/messaging-api/#get-number-of-followers)|GetNumberOfFollowersAsync|✔|
71-
|[Get friend demographics](https://developers.line.biz/en/reference/messaging-api/#get-demographic)|GetFriendsDemographicsAsync||
72-
|[Get user interaction statistics](https://developers.line.biz/en/reference/messaging-api/#get-message-event)|GetUserInteractionStatisticsAsync||
73-
|[Get statistics per unit](https://developers.line.biz/en/reference/messaging-api/#get-statistics-per-unit)|GetStatisticsPerUnitAsync||
71+
|[Get friend demographics](https://developers.line.biz/en/reference/messaging-api/#get-demographic)|GetFriendsDemographicsAsync||
72+
|[Get user interaction statistics](https://developers.line.biz/en/reference/messaging-api/#get-message-event)|GetUserInteractionStatisticsAsync||
73+
|[Get statistics per unit](https://developers.line.biz/en/reference/messaging-api/#get-statistics-per-unit)|GetStatisticsPerUnitAsync||
7474
7575
### 2-1-3. LineRichMenuClient class
7676
* [Rich menu](https://developers.line.biz/en/reference/messaging-api/#rich-menu)

README_kor.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ Install-Package LineDevelopers
6565
|---|---|---|
6666
|[Get number of message deliveries](https://developers.line.biz/en/reference/messaging-api/#get-number-of-delivery-messages)|GetNumberOfMessageDeliveriesAsync|✔|
6767
|[Get number of followers](https://developers.line.biz/en/reference/messaging-api/#get-number-of-followers)|GetNumberOfFollowersAsync|✔|
68-
|[Get friend demographics](https://developers.line.biz/en/reference/messaging-api/#get-demographic)|GetFriendsDemographicsAsync||
69-
|[Get user interaction statistics](https://developers.line.biz/en/reference/messaging-api/#get-message-event)|GetUserInteractionStatisticsAsync||
70-
|[Get statistics per unit](https://developers.line.biz/en/reference/messaging-api/#get-statistics-per-unit)|GetStatisticsPerUnitAsync||
68+
|[Get friend demographics](https://developers.line.biz/en/reference/messaging-api/#get-demographic)|GetFriendsDemographicsAsync||
69+
|[Get user interaction statistics](https://developers.line.biz/en/reference/messaging-api/#get-message-event)|GetUserInteractionStatisticsAsync||
70+
|[Get statistics per unit](https://developers.line.biz/en/reference/messaging-api/#get-statistics-per-unit)|GetStatisticsPerUnitAsync||
7171
7272
### 2-1-3. LineRichMenuClient class
7373
* [Rich menu](https://developers.line.biz/en/reference/messaging-api/#rich-menu)

Src/LineDevelopers.ConsoleTests/Program.cs

Lines changed: 65 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,91 @@
1-
using System.Text.Json;
1+
using System.Net.Http.Headers;
2+
using System.Text.Json;
23
using Line;
34
using Line.Login;
45
using Line.Message;
56

67
var json = File.ReadAllText(@"c:\temp\test.json");
78
var config = JsonSerializer.Deserialize<TestConfig>(json);
89

9-
using (var client = new LineMessagingClient("your channelacesstoken"))
10-
{
11-
await client.Message.SendPushMessageAsync("user id", new TextMessage("hello world"));
12-
}
13-
14-
15-
using (var client = new LineMessagingClient("your channelacesstoken"))
16-
{
17-
await client.Message.SendPushMessageAsync("user id", new TextMessage("hello world"),
18-
xLineRetryKey: Guid.NewGuid().ToString());
19-
}
2010

21-
using (var client = new LineMessagingClient("your channelacesstoken"))
11+
using (var client = new LineMessagingClient(config.ChannelAccessToken))
2212
{
23-
await client.Message.SendPushMessageAsync("user id", new TextMessage("hello world"),
24-
xLineRetryKey: Guid.NewGuid().ToString(),
25-
getResponseHeaders: (o) =>
26-
{
27-
IEnumerable<string> xLineRequestId;
28-
IEnumerable<string> xLineAcceptedRequestId;
29-
30-
if (o.TryGetValues("X-Line-Request-Id", out xLineRequestId))
13+
string requestId = String.Empty;
14+
15+
var messages = new List<IMessage>()
16+
{
17+
new TextMessage("first"),
18+
new StickerMessage("6632","11825375")
19+
{
20+
QuickReply = new QuickReply()
3121
{
32-
Console.WriteLine(xLineRequestId.First());
22+
Items = new List<QuickReplyButtonObject>()
23+
{
24+
new QuickReplyButtonObject()
25+
{
26+
Action = new UriAction()
27+
{
28+
Label = "test label",
29+
Uri = "http://lunasoft.co.kr"
30+
}
31+
}
32+
}
3333
}
34+
}
35+
};
3436

35-
if (o.TryGetValues("X-Line-Accepted-Request-Id", out xLineAcceptedRequestId))
37+
await client.Message.SendBroadcastMessageAsync(messages,
38+
getResponseHeaders: async (o) =>
3639
{
37-
Console.WriteLine(xLineAcceptedRequestId.First());
38-
}
39-
});
40-
}
40+
IEnumerable<string> xLineRequestId;
4141

42+
if (o.TryGetValues("X-Line-Request-Id", out xLineRequestId))
43+
{
44+
requestId = xLineRequestId.First();
4245

46+
Console.WriteLine(requestId);
47+
}
48+
});
4349

50+
try
51+
{
52+
await Task.Delay(60000);
4453

45-
using (var test = new LineMessagingClient(config.ChannelAccessToken))
46-
{
47-
await test.Message.SendPushMessageAsync("", new TextMessage("fdasfds"),
48-
getResponseHeaders: (o) =>
49-
{
50-
IEnumerable<string> xLineRequestId;
51-
IEnumerable<string> xLineAcceptedRequestId;
54+
var result = await client.Insight.GetUserInteractionStatisticsAsync(requestId);
5255

53-
if (o.TryGetValues("X-Line-Request-Id", out xLineRequestId))
54-
{
55-
Console.WriteLine(xLineRequestId.First());
56-
}
56+
Console.WriteLine(result.Overview.RequestId);
5757

58-
if (o.TryGetValues("X-Line-Accepted-Request-Id", out xLineAcceptedRequestId))
59-
{
60-
Console.WriteLine(xLineAcceptedRequestId.First());
61-
}
62-
});
58+
}
59+
catch (LineException ex)
60+
{
61+
Console.WriteLine(ex.Message);
62+
}
6363
}
6464

6565

6666

67+
//using (var test = new LineMessagingClient(config.ChannelAccessToken))
68+
//{
69+
// await test.Message.SendPushMessageAsync("", new TextMessage("fdasfds"),
70+
// getResponseHeaders: (o) =>
71+
// {
72+
// IEnumerable<string> xLineRequestId;
73+
// IEnumerable<string> xLineAcceptedRequestId;
74+
75+
// if (o.TryGetValues("X-Line-Request-Id", out xLineRequestId))
76+
// {
77+
// Console.WriteLine(xLineRequestId.First());
78+
// }
79+
80+
// if (o.TryGetValues("X-Line-Accepted-Request-Id", out xLineAcceptedRequestId))
81+
// {
82+
// Console.WriteLine(xLineAcceptedRequestId.First());
83+
// }
84+
// });
85+
//}
86+
87+
88+
6789

6890
//using (LineLoginClient client = new LineLoginClient())
6991
//{

Src/LineDevelopers.Tests/LineInsightClientTest.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,39 @@ public async Task GetNumberOfMessageDeliveriesAsync()
1919
}
2020

2121
[Test]
22-
public void GetUserInteractionStatisticsAsyncTest()
22+
public void GetUserInteractionStatisticsAsyncErrorTest()
2323
{
2424
var ex = ThrowsAsync<LineException>(() => _client.Insight.GetUserInteractionStatisticsAsync("NOT EXISTS REQ ID"));
2525

2626
That("Not Found", Is.EqualTo(ex.Message));
2727
}
2828

29+
[Test]
30+
public void GetUserInteractionStatisticsAsyncTest()
31+
{
32+
DoesNotThrowAsync(async () =>
33+
{
34+
string requestId = String.Empty;
35+
36+
await _client.Message.SendBroadcastMessageAsync(new TextMessage("static test"),
37+
getResponseHeaders: async (o) =>
38+
{
39+
IEnumerable<string> xLineRequestId;
40+
41+
if (o.TryGetValues("X-Line-Request-Id", out xLineRequestId))
42+
{
43+
requestId = xLineRequestId.First();
44+
}
45+
});
46+
47+
await Task.Delay(1000);
48+
49+
var result = await _client.Insight.GetUserInteractionStatisticsAsync(requestId);
50+
51+
That(result.Overview.RequestId, Is.EqualTo(requestId));
52+
});
53+
}
54+
2955
[Test]
3056
public void GetStatisticsPerUnitAsyncTest()
3157
{

Src/LineDevelopers.Webhook.Tests/Controllers/LineController.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,14 @@ protected override async Task OnMemberLeaveEventAsync(MemberLeaveEventObject mem
7777

7878
protected override async Task OnMessageEventAsync(MessageEventObject messageEventObject)
7979
{
80-
string key = "";
81-
82-
await SomeOtherMethod("ddd", "ddd");
83-
84-
85-
await SomeOtherMethod("ddd", "ddd", (o) => {
86-
key = o;
87-
});
88-
89-
var aaa = key;
90-
91-
9280
IMessage message;
9381

9482
switch (messageEventObject.Message)
9583
{
9684
case TextObject:
9785
var text = (TextObject)messageEventObject.Message;
9886
message = new TextMessage(text.Text);
87+
9988
break;
10089
case StickerObject:
10190
var sticker = (StickerObject)messageEventObject.Message;

Src/LineDevelopers/LineDevelopers.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net7.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<AssemblyVersion>1.1.10</AssemblyVersion>
7+
<AssemblyVersion>1.1.20</AssemblyVersion>
88
<PackageProjectUrl>https://github.com/charles96/LineDevelopers.NET</PackageProjectUrl>
99
<Title>LineDevelopers.NET</Title>
1010
<Authors>Charles Hong</Authors>
@@ -13,7 +13,7 @@
1313
<PackageTags>LINE;LINE Messaging;LINE Developers;Chatbot;LIFF</PackageTags>
1414
<RepositoryType>git</RepositoryType>
1515
<RootNamespace>Line</RootNamespace>
16-
<Version>1.1.10</Version>
16+
<Version>1.1.20</Version>
1717
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
1818
<PackageReadmeFile>README.md</PackageReadmeFile>
1919
</PropertyGroup>
@@ -29,4 +29,8 @@
2929
</None>
3030
</ItemGroup>
3131

32+
<ItemGroup>
33+
<Folder Include="Message\Content\" />
34+
</ItemGroup>
35+
3236
</Project>

Src/LineDevelopers/LineHttpClient.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public LineHttpClient(double timeout = 100d)
1616
{
1717
_httpClient = new HttpClient();
1818
_httpClient.BaseAddress = new Uri("https://api.line.me/");
19+
_httpClient.DefaultRequestVersion = new Version(2, 0);
1920
_httpClient.Timeout = TimeSpan.FromSeconds(timeout);
2021

2122
_jsonSerializerOptions = new JsonSerializerOptions();
@@ -70,6 +71,7 @@ protected async Task<TResult> GetAsync<TResult>(string endpoint, HttpContent htt
7071

7172
using (var request = new HttpRequestMessage(HttpMethod.Get, endpoint))
7273
{
74+
request.Version = new Version(2, 0);
7375
request.Content = httpContent;
7476

7577
using (var response = await _httpClient.SendAsync(request).ConfigureAwait(false))
@@ -87,11 +89,13 @@ protected async Task<TResult> GetAsync<TResult>(string endpoint, string? headerN
8789
{
8890
TResult result;
8991

90-
using (var body = new HttpRequestMessage(HttpMethod.Get, endpoint))
92+
using (var request = new HttpRequestMessage(HttpMethod.Get, endpoint))
9193
{
92-
if (!String.IsNullOrWhiteSpace(headerName)) body.Headers.Add(headerName, headerValue);
94+
request.Version = new Version(2, 0);
9395

94-
using (var response = await _httpClient.SendAsync(body).ConfigureAwait(false))
96+
if (!String.IsNullOrWhiteSpace(headerName)) request.Headers.Add(headerName, headerValue);
97+
98+
using (var response = await _httpClient.SendAsync(request).ConfigureAwait(false))
9599
{
96100
GetHeaders(response, getResponseHeaders);
97101
await this.EnsureSuccessStatusCodeAsync(response).ConfigureAwait(false);
@@ -111,12 +115,24 @@ protected async Task<Stream> GetStreamAsync(string endpoint, Action<HttpResponse
111115
return await response.Content?.ReadAsStreamAsync();
112116
}
113117

118+
protected async Task<Stream> GetStreamAsync(string endpoint, Action<HttpContentHeaders,HttpResponseHeaders>? getResponseHeaders = null)
119+
{
120+
var response = await _httpClient.GetAsync(endpoint).ConfigureAwait(false);
121+
122+
if (getResponseHeaders != null) getResponseHeaders(response.Content.Headers, response.Headers);
123+
124+
await this.EnsureSuccessStatusCodeAsync(response).ConfigureAwait(false);
125+
126+
return await response.Content?.ReadAsStreamAsync();
127+
}
128+
114129
protected async Task PostAsync(string endpoint, StreamContent streamContent, MediaType mediaType, Action<HttpResponseHeaders>? getResponseHeaders = null)
115130
{
116131
using (var request = new HttpRequestMessage(HttpMethod.Post, endpoint))
117132
{
118133
streamContent.Headers.Add("Content-Type", mediaType == MediaType.Jpg ? "image/jpeg" : "image/png");
119-
134+
135+
request.Version = new Version(2, 0);
120136
request.Content = streamContent;
121137

122138
using (var response = await _httpClient.SendAsync(request).ConfigureAwait(false))
@@ -177,7 +193,9 @@ protected async Task PostAsJsonAsync<TRequest>(string endpoint, TRequest request
177193
using (var body = new HttpRequestMessage(HttpMethod.Post, endpoint))
178194
{
179195
var json = JsonSerializer.Serialize<TRequest>(request, _jsonSerializerOptions);
196+
180197
body.Content = new StringContent(json, Encoding.UTF8, "application/json");
198+
body.Version = new Version(2, 0);
181199

182200
if (!String.IsNullOrWhiteSpace(headerName)) body.Headers.Add(headerName, headerValue);
183201

Src/LineDevelopers/Message/Insights/StatisticsMessage.cs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,49 @@ namespace Line.Message
55
public class StatisticsMessage
66
{
77
[JsonPropertyName("seq")]
8-
public int seq { get; set; }
8+
public int Seq { get; set; }
99

1010
[JsonPropertyName("impression")]
11-
public int impression { get; set; }
11+
public int Impression { get; set; }
1212

1313
[JsonPropertyName("mediaPlayed")]
14-
public int mediaPlayed { get; set; }
14+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
15+
public int? MediaPlayed { get; set; }
1516

1617
[JsonPropertyName("mediaPlayed25Percent")]
17-
public int mediaPlayed25Percent { get; set; }
18+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
19+
public int? MediaPlayed25Percent { get; set; }
1820

1921
[JsonPropertyName("mediaPlayed50Percent")]
20-
public int mediaPlayed50Percent { get; set; }
22+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
23+
public int? MediaPlayed50Percent { get; set; }
2124

2225
[JsonPropertyName("mediaPlayed75Percent")]
23-
public int mediaPlayed75Percent { get; set; }
26+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
27+
public int? MediaPlayed75Percent { get; set; }
2428

2529
[JsonPropertyName("mediaPlayed100Percent")]
26-
public int mediaPlayed100Percent { get; set; }
30+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
31+
public int? MediaPlayed100Percent { get; set; }
32+
33+
[JsonPropertyName("uniqueMediaPlayed")]
34+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
35+
public int? UniqueMediaPlayed { get; set; }
36+
37+
[JsonPropertyName("uniqueMediaPlayed25Percent")]
38+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
39+
public int? UniqueMediaPlayed25Percent { get; set; }
40+
41+
[JsonPropertyName("uniqueMediaPlayed50Percent")]
42+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
43+
public int? UniqueMediaPlayed50Percent { get; set; }
44+
45+
[JsonPropertyName("uniqueMediaPlayed75Percent")]
46+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
47+
public int? UniqueMediaPlayed75Percent { get; set; }
48+
49+
[JsonPropertyName("uniqueMediaPlayed100Percent")]
50+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
51+
public int? UniqueMediaPlayed100Percent { get; set; }
2752
}
2853
}

0 commit comments

Comments
 (0)