511 lines
15 KiB
C#
511 lines
15 KiB
C#
using System;
|
|
using Newtonsoft.Json;
|
|
using xCommons.Extensions;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace xBotService.Models
|
|
{
|
|
/// <summary>
|
|
/// Represent XBot Response User ...
|
|
/// </summary>
|
|
public class XBotResUser
|
|
{
|
|
[JsonProperty("id",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public long Id { get; set; }
|
|
|
|
[JsonProperty("is_bot",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public bool IsBot { get; set; }
|
|
|
|
[JsonProperty("last_name",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public string LastName { get; set; }
|
|
|
|
[JsonProperty("username",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public string Username { get; set; }
|
|
|
|
[JsonProperty("first_name",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public string FirstName { get; set; }
|
|
|
|
[JsonProperty("language_code",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public string LanguageCode { get; set; }
|
|
|
|
[JsonProperty("has_main_web_app",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public string HasMainWebApp { get; set; }
|
|
|
|
[JsonProperty("has_topics_enabled",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public bool HasTopicsEnabled { get; set; }
|
|
|
|
[JsonProperty("allows_users_to_create_topics",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public bool AllowsUsersToCreateTopics { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Base Bot Response ...
|
|
/// </summary>
|
|
public class XBotResponse : XBotResponse<object>
|
|
{ }
|
|
|
|
/// <summary>
|
|
/// Base Bot Response ...
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
public class XBotResponse<T>
|
|
{
|
|
public bool Ok { get; set; }
|
|
public T Result { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bot Update Request ...
|
|
/// </summary>
|
|
public class XBotUpdatesRequest
|
|
{
|
|
[JsonProperty("limit")]
|
|
public int Limit { get; set; } = 100;
|
|
|
|
[JsonProperty("offset")]
|
|
public long Offset { get; set; } = 0;
|
|
|
|
[JsonProperty("timeout")]
|
|
public int Timeout { get; set; } = 30;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Represent an Event in Bot ...
|
|
/// </summary>
|
|
public class XBotUpdateResponse
|
|
{
|
|
[JsonProperty("update_id",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public long UpdateId { get; set; }
|
|
|
|
[JsonProperty("message",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public XBotMessage Message { get; set; }
|
|
|
|
[JsonProperty("edited_message",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public XBotMessage EditedMessage { get; set; }
|
|
|
|
[JsonProperty("callback_query",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public XBotCallbackQuery CallbackQuery { get; set; }
|
|
|
|
[JsonProperty("pre_checkout_query",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object PreCheckoutQuery { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
//
|
|
var result = string.Empty;
|
|
if (this.IsNull())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = $"{nameof(XBotUpdateResponse)}:{Environment.NewLine}";
|
|
result += $"{nameof(UpdateId)}: {UpdateId}{Environment.NewLine}";
|
|
result += $"{nameof(Message)}: {Message}{Environment.NewLine}";
|
|
result += $"{nameof(EditedMessage)}: {EditedMessage}{Environment.NewLine}";
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Represent a Bot MEssage ...
|
|
/// </summary>
|
|
public class XBotMessage
|
|
{
|
|
[JsonProperty("message_id",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public long MessageId { get; set; }
|
|
|
|
[JsonProperty("message_thread_id",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public long MessageThreadId { get; set; }
|
|
|
|
[JsonProperty("from",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public XBotResUser From { get; set; }
|
|
|
|
[JsonProperty("date",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public long Date { get; set; }
|
|
|
|
[JsonProperty("chat",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object Chat { get; set; }
|
|
|
|
[JsonProperty("sender_chat",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object SenderChat { get; set; }
|
|
|
|
[JsonProperty("forward_from",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public XBotResUser ForwardFrom { get; set; }
|
|
|
|
[JsonProperty("forward_from_chat",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object ForwardFromChat { get; set; }
|
|
|
|
[JsonProperty("forward_from_message_id",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public long ForwardFromMessageId { get; set; }
|
|
|
|
[JsonProperty("forward_date",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public long ForwardDate { get; set; }
|
|
|
|
[JsonProperty("reply_to_message",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public XBotMessage ReplyToMessage { get; set; }
|
|
|
|
[JsonProperty("edit_date",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public long EditDate { get; set; }
|
|
|
|
[JsonProperty("media_group_id",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public string MediaGroupId { get; set; }
|
|
|
|
[JsonProperty("text",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public string Text { get; set; }
|
|
|
|
[JsonProperty("entities",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public IList<object> Entities { get; set; }
|
|
|
|
[JsonProperty("animation",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object Animation { get; set; }
|
|
|
|
[JsonProperty("audio",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object Audio { get; set; }
|
|
|
|
[JsonProperty("document",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object Document { get; set; }
|
|
|
|
[JsonProperty("photo",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public IList<object> Photo { get; set; }
|
|
|
|
[JsonProperty("sticker",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object Sticker { get; set; }
|
|
|
|
[JsonProperty("video",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object Video { get; set; }
|
|
|
|
[JsonProperty("voice",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object Voice { get; set; }
|
|
|
|
[JsonProperty("caption",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public string Caption { get; set; }
|
|
|
|
[JsonProperty("caption_entities",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public IList<object> CaptionEntities { get; set; }
|
|
|
|
[JsonProperty("contact",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object Contact { get; set; }
|
|
|
|
[JsonProperty("location",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object Location { get; set; }
|
|
|
|
[JsonProperty("new_chat_members",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public IList<XBotResUser> NewChatMembers { get; set; }
|
|
|
|
[JsonProperty("left_chat_member",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public XBotResUser LeftChatMember { get; set; }
|
|
|
|
[JsonProperty("invoice",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object Invoice { get; set; }
|
|
|
|
[JsonProperty("successful_payment",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object SuccessfulPayment { get; set; }
|
|
|
|
[JsonProperty("web_app_data",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object WebAppData { get; set; }
|
|
|
|
[JsonProperty("reply_markup",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object ReplyMarkup { get; set; }
|
|
|
|
[JsonProperty("forum_topic_created",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object ForumTopicCreated { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
//
|
|
if (this.IsNull())
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
//
|
|
var from = !From.IsNull()
|
|
? nameof(From) + ":" + From.Id + "," + From.Username + From.FirstName + From.LastName
|
|
: string.Empty;
|
|
var result = $"""
|
|
{nameof(MessageId)}: {MessageId}, {Environment.NewLine}
|
|
{nameof(Text)}: {Text}, {Environment.NewLine}
|
|
""";
|
|
if (!from.IsNullOrEmpty())
|
|
{
|
|
result += from + Environment.NewLine;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// a Callbacked From a Inline Keyboard ...
|
|
/// </summary>
|
|
public class XBotCallbackQuery
|
|
{
|
|
[JsonProperty("id",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public string Id { get; set; }
|
|
|
|
[JsonProperty("data",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public string Data { get; set; }
|
|
|
|
[JsonProperty("from",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public XBotResUser From { get; set; }
|
|
|
|
[JsonProperty("message",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public XBotMessage Message { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bot Message Send Request ...
|
|
/// </summary>
|
|
public class XBotSendMessageRequest
|
|
{
|
|
public long ChatId { get; set; }
|
|
public string Text { get; set; }
|
|
public object ReplyMarkup { get; set; }
|
|
public long MessageThreadId { get; set; }
|
|
public long ReplyToMessageId { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bot Message Send Request ...
|
|
/// </summary>
|
|
public class XBotSendMessageRequestDto
|
|
{
|
|
[JsonProperty("chat_id",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public long ChatId { get; set; }
|
|
|
|
[JsonProperty("text",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public string Text { get; set; }
|
|
|
|
[JsonProperty("reply_markup",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object ReplyMarkup { get; set; }
|
|
|
|
[JsonProperty("message_thread_id",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public long MessageThreadId { get; set; }
|
|
|
|
[JsonProperty("reply_to_message_id",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public long ReplyToMessageId { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// a Bot Button Keyboard ...
|
|
/// </summary>
|
|
public class XBotKeyboardButton
|
|
{
|
|
[JsonProperty("text",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public string Text { get; set; }
|
|
|
|
[JsonProperty("style",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public string Style { get; set; }
|
|
|
|
[JsonProperty("request_contact",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public bool RequestContact { get; set; }
|
|
|
|
[JsonProperty("request_location",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public bool RequestLocation { get; set; }
|
|
|
|
[JsonProperty("web_app",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public XBotWebAppInfo WebApp { get; set; } = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// XBot Web App Info ...
|
|
/// </summary>
|
|
public class XBotWebAppInfo
|
|
{
|
|
public string Url { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// a Bot Copy Text Button ...
|
|
/// </summary>
|
|
public class XBotCopyTextButton
|
|
{
|
|
[StringLength(256)]
|
|
public string Text { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// An Inline Keyboard Button ...
|
|
/// </summary>
|
|
public class XBotInlineKeyboardButton
|
|
{
|
|
[JsonProperty("url",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public string Url { get; set; }
|
|
|
|
[JsonProperty("text",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public string Text { get; set; }
|
|
|
|
[JsonProperty("style",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public string Style { get; set; }
|
|
|
|
[JsonProperty("callback_data",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public string CallbackData { get; set; }
|
|
|
|
[JsonProperty("disabled",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public object Disabled { get; set; } = null;
|
|
|
|
[JsonProperty("web_app",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public XBotWebAppInfo WebApp { get; set; } = null;
|
|
|
|
[JsonProperty("copy_text",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public XBotCopyTextButton CopyText { get; set; } = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bot Inline Keyboard ...
|
|
/// </summary>
|
|
public class XBotInlineKeyboardMarkup
|
|
{
|
|
[JsonProperty("inline_keyboard",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public IList<IList<XBotInlineKeyboardButton>> InlineKeyboard { get; set; } = [];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bot Reply Keyboard Markup ...
|
|
/// </summary>
|
|
public class XBotReplyKeyboardMarkup
|
|
{
|
|
[JsonProperty("keyboard",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public IList<XBotKeyboardButton> Keyboard { get; set; } = [];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reply Bot Keyboard Remove ...
|
|
/// </summary>
|
|
public class XBotReplyKeyboardRemoveMarkup
|
|
{
|
|
[JsonProperty("remove_keyboard",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public bool RemoveKeyboard { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bot Reply Markup ...
|
|
/// </summary>
|
|
public class XBotReplyMarkup
|
|
{
|
|
[JsonProperty("reply_markup",
|
|
NullValueHandling = NullValueHandling.Ignore)]
|
|
public IList<XBotKeyboardButton> Keyboard { get; set; } = [];
|
|
public object ReplyMarkup { get; set; }
|
|
|
|
public static XBotReplyMarkup InlineKeyboardMarkup(
|
|
XBotInlineKeyboardMarkup source
|
|
)
|
|
{
|
|
//
|
|
var result = new XBotReplyMarkup
|
|
{
|
|
ReplyMarkup = source
|
|
};
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
public static XBotReplyMarkup ReplyKeyboardMarkup(
|
|
XBotReplyKeyboardMarkup source
|
|
)
|
|
{
|
|
//
|
|
var data = source.ToJSON();
|
|
var result = new XBotReplyMarkup
|
|
{
|
|
ReplyMarkup = data
|
|
};
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
public static XBotReplyMarkup ReplyKeyboardRemoveMarkup(
|
|
XBotReplyKeyboardRemoveMarkup source
|
|
)
|
|
{
|
|
//
|
|
var data = source.ToJSON();
|
|
var result = new XBotReplyMarkup
|
|
{
|
|
ReplyMarkup = data
|
|
};
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|
|
} |