Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add specific object into list message #50

Merged
merged 14 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/Sinch/Conversation/Messages/Message/ListMessage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;
using Sinch.Core;

namespace Sinch.Conversation.Messages.Message
Expand Down Expand Up @@ -72,7 +74,7 @@ public sealed class ListSection
/// <summary>
/// Gets or Sets Items
/// </summary>
public List<IListItem> Items { get; set; }
public List<ListItem> Items { get; set; }
JPPortier marked this conversation as resolved.
Show resolved Hide resolved


/// <summary>
Expand All @@ -95,6 +97,31 @@ public interface IListItem
{
}

public class ListItem
JPPortier marked this conversation as resolved.
Show resolved Hide resolved
{
[Obsolete("Required for System.Text.Json", true)]
public ListItem()
{

}

[JsonInclude]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ListItemChoice Choice { get; private set; }
public ListItem(ListItemChoice listItemChoice)
{
Choice = listItemChoice;
}

[JsonInclude]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ListItemProduct Product { get; private set; }
public ListItem(ListItemProduct listItemProduct)
{
Product = listItemProduct;
}
}

/// <summary>
/// Additional properties for the message. Required if sending a product list message.
/// </summary>
Expand Down
34 changes: 20 additions & 14 deletions tests/Sinch.Tests/Conversation/MessagesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public async Task GetMessage()
new ListSection()
{
Title = "sec1",
Items = new List<IListItem>()
Items = new List<ListItem>()
{
new ListItemChoice()
new(new ListItemChoice()
{
Title = "title",
Description = "desc",
Expand All @@ -54,19 +54,19 @@ public async Task GetMessage()
Url = new Uri("http://localhost")
},
PostbackData = "postback"
}
})
}
},
new ListSection()
{
Title = "sec2",
Items = new List<IListItem>()
Items = new List<ListItem>()
{
new ListItemProduct()
new(new ListItemProduct()
{
Id = "id",
Marketplace = "amazon"
}
})
}
}
}
Expand Down Expand Up @@ -208,13 +208,16 @@ private static object Message()
{
new
{
title = "title",
description = "desc",
media = new
choice = new
{
url = "http://localhost",
},
postback_data = "postback"
title = "title",
description = "desc",
media = new
{
url = "http://localhost",
},
postback_data = "postback"
}
}
}
},
Expand All @@ -225,8 +228,11 @@ private static object Message()
{
new
{
id = "id",
marketplace = "amazon"
product = new
{
id = "id",
marketplace = "amazon"
}
}
}
}
Expand Down
38 changes: 22 additions & 16 deletions tests/Sinch.Tests/Conversation/SendMessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,22 +344,28 @@ public async Task SendList()
{
new
{
title = "listitemchoice",
postback_data = "postno",
description = "desc",
media = new
choice = new
{
url = "https://nolocalhost",
thumbnail_url = "https://knowyourmeme.com/photos/377946"
title = "listitemchoice",
postback_data = "postno",
description = "desc",
media = new
{
url = "https://nolocalhost",
thumbnail_url = "https://knowyourmeme.com/photos/377946"
}
}
},
new
{
id = "prod_id",
marketplace = "amazon",
currency = "eur",
quantity = 20,
item_price = 12.1000004f,
product = new
{
id = "prod_id",
marketplace = "amazon",
currency = "eur",
quantity = 20,
item_price = 12.1000004f,
}
}
}
}
Expand All @@ -374,9 +380,9 @@ public async Task SendList()
new ListSection()
{
Title = "item1",
Items = new List<IListItem>()
Items = new List<ListItem>()
{
new ListItemChoice()
new(new ListItemChoice()
{
Title = "listitemchoice",
PostbackData = "postno",
Expand All @@ -386,15 +392,15 @@ public async Task SendList()
Url = new Uri("https://nolocalhost"),
ThumbnailUrl = new Uri("https://knowyourmeme.com/photos/377946")
}
},
new ListItemProduct
}),
new(new ListItemProduct
{
Id = "prod_id",
Marketplace = "amazon",
Currency = "eur",
Quantity = 20,
ItemPrice = 12.1000004f,
}
})
}
}
},
Expand Down
Loading