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 7 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
12 changes: 12 additions & 0 deletions 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 @@ -95,6 +97,16 @@ public interface IListItem
{
}

public class ListItemChoiceWrapper : IListItem
JPPortier marked this conversation as resolved.
Show resolved Hide resolved
{
public ListItemChoice Choice { get; set; }
}

public class ListItemProductWrapper : IListItem
{
public ListItemProduct Product { get; set; }
JPPortier marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
/// Additional properties for the message. Required if sending a product list message.
/// </summary>
Expand Down
50 changes: 31 additions & 19 deletions tests/Sinch.Tests/Conversation/MessagesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,33 @@ public async Task GetMessage()
Title = "sec1",
Items = new List<IListItem>()
{
new ListItemChoice()
new ListItemChoiceWrapper
{
Title = "title",
Description = "desc",
Media = new MediaMessage()
Choice = new ListItemChoice()
JPPortier marked this conversation as resolved.
Show resolved Hide resolved
{
Url = new Uri("http://localhost")
},
PostbackData = "postback"
Title = "title",
Description = "desc",
Media = new MediaMessage()
{
Url = new Uri("http://localhost")
},
PostbackData = "postback"
}
}
}
},
new ListSection()
{
Title = "sec2",
Items = new List<IListItem>()
Items = new List<IListItem>
{
new ListItemProduct()
new ListItemProductWrapper()
{
Id = "id",
Marketplace = "amazon"
Product = new ListItemProduct()
{
Id = "id",
Marketplace = "amazon"
}
}
}
}
Expand Down Expand Up @@ -208,13 +214,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 +234,11 @@ private static object Message()
{
new
{
id = "id",
marketplace = "amazon"
product = new
{
id = "id",
marketplace = "amazon"
}
}
}
}
Expand Down
60 changes: 36 additions & 24 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 @@ -376,24 +382,30 @@ public async Task SendList()
Title = "item1",
Items = new List<IListItem>()
{
new ListItemChoice()
new ListItemChoiceWrapper
{
Title = "listitemchoice",
PostbackData = "postno",
Description = "desc",
Media = new MediaMessage()
Choice = new ListItemChoice()
{
Url = new Uri("https://nolocalhost"),
ThumbnailUrl = new Uri("https://knowyourmeme.com/photos/377946")
Title = "listitemchoice",
PostbackData = "postno",
Description = "desc",
Media = new MediaMessage()
{
Url = new Uri("https://nolocalhost"),
ThumbnailUrl = new Uri("https://knowyourmeme.com/photos/377946")
}
}
},
new ListItemProduct
new ListItemProductWrapper()
{
Id = "prod_id",
Marketplace = "amazon",
Currency = "eur",
Quantity = 20,
ItemPrice = 12.1000004f,
Product = new ListItemProduct
{
Id = "prod_id",
Marketplace = "amazon",
Currency = "eur",
Quantity = 20,
ItemPrice = 12.1000004f,
}
}
}
}
Expand Down
Loading