-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
177 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Net.Mime; | ||
using System.Text.Json.Serialization; | ||
using HeyBoxChatBotCs.Api.Enums; | ||
|
||
namespace HeyBoxChatBotCs.Api.Features.Message; | ||
|
||
public class ImageMessage : MessageBase | ||
{ | ||
public ImageMessage(string image, string channelId, string roomId, string replyMessageId = "", string? ackId = null) | ||
: this(new Uri(image), | ||
channelId, roomId, replyMessageId, ackId) | ||
{ | ||
} | ||
|
||
public ImageMessage(Uri image, Channel channelId, Room roomId, string replyMessageId = "", string? ackId = null) : | ||
this(image, | ||
channelId.Id, roomId.Id, replyMessageId, ackId) | ||
{ | ||
} | ||
|
||
public ImageMessage(Uri image, string channelId, string roomId, string replyMessageId = "", | ||
string? ackId = null) : base( | ||
ackId ?? MessageAck.GetAckId(), MessageType.Image, channelId, roomId, replyMessageId) | ||
{ | ||
Uri = image; | ||
} | ||
|
||
[JsonPropertyName("img")] public Uri Uri { get; init; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,60 @@ | ||
using System.Text.Json.Serialization; | ||
using System.Text.Encodings.Web; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using HeyBoxChatBotCs.Api.Enums; | ||
|
||
namespace HeyBoxChatBotCs.Api.Features.Message; | ||
|
||
[JsonDerivedType(typeof(MarkdownMessage))] | ||
[JsonDerivedType(typeof(ImageMessage))] | ||
public abstract class MessageBase | ||
{ | ||
protected MessageBase(string ackId, MessageType type, string channelId, string roomId) | ||
protected MessageBase(string ackId, MessageType type, string channelId, string roomId, string replyMessageId = "", | ||
MessageAddition? addition = null) | ||
{ | ||
ReplyMessageId = replyMessageId; | ||
AckId = ackId; | ||
Type = type; | ||
ChannelId = channelId; | ||
RoomId = roomId; | ||
Addition = JsonSerializer.Serialize(addition ?? new MessageAddition(), Bot.Bot.BotActionJsonSerializerOptions); | ||
} | ||
|
||
|
||
[JsonPropertyName("reply_id")] public string ReplyMessageId { get; init; } | ||
[JsonPropertyName("heychat_ack_id")] public string AckId { get; init; } | ||
[JsonPropertyName("msg_type")] public MessageType Type { get; init; } | ||
[JsonPropertyName("channel_id")] public string ChannelId { get; init; } | ||
[JsonPropertyName("room_id")] public string RoomId { get; init; } | ||
|
||
[JsonPropertyName("addition")] public string Addition { get; init; } | ||
} | ||
|
||
public class MessageAddition | ||
{ | ||
public MessageAddition(MessageAdditionImage[]? additionImages = null) | ||
{ | ||
ImageFilesInfo = additionImages ?? []; | ||
} | ||
|
||
[JsonPropertyName("img_files_info")] public MessageAdditionImage[] ImageFilesInfo { get; init; } | ||
} | ||
|
||
public class MessageAdditionImage | ||
{ | ||
public MessageAdditionImage(string uri, int width, int height) : this(new Uri(uri), width, | ||
height) | ||
{ | ||
} | ||
|
||
public MessageAdditionImage(Uri uri, int width, int height) | ||
{ | ||
Uri = uri; | ||
Width = width; | ||
Height = height; | ||
} | ||
|
||
[JsonPropertyName("uri")] public Uri Uri { get; init; } | ||
[JsonPropertyName("width")] public int Width { get; init; } | ||
[JsonPropertyName("height")] public int Height { get; init; } | ||
} |
Oops, something went wrong.