public static void CallbackQueryTest()
        {
            //field class UserInfo
            const int id = 123;
            const bool isBot = true;
            const string idСallback = "123";
            const string firstName = "TestFirstName";
            const string lastName = "TestLastName";
            const string username = "******";
            const string languageCode = "TestLanguageCode";

            //field class MessageInfo
            const int messageId = 123;
            const int date = 0;
            const int chatId = 123;
            const ChatType chatType = ChatType.channel;

            //field class CallbackQueryInfo
            const string inlineMessageId = "123";
            const string chatInstance = "123";
            const string data = "TestData";
            const string gameShortName = "TestGameShortName";
            
            JObject userInfo = UserInfoObject.GetObject(id, isBot, firstName, lastName, username, languageCode);
            JObject messageInfo = MessageInfoObject.GetMandatoryFieldsMessageInfo(messageId, date, chatId, chatType);

            dynamic callbackQueryInfo = CallbackQueryInfoObject.GetObject(idСallback, userInfo, messageInfo, inlineMessageId,
                chatInstance, data, gameShortName);

            CallbackQueryInfo callbackQuery = new CallbackQueryInfo(callbackQueryInfo);

            Assert.Multiple(() =>
            {
                //UserInfo field
                Assert.AreEqual(id, callbackQuery.From.Id);
                Assert.AreEqual(isBot, callbackQuery.From.IsBot);
                Assert.AreEqual(firstName, callbackQuery.From.FirstName);
                Assert.AreEqual(lastName, callbackQuery.From.LastName);
                Assert.AreEqual(username, callbackQuery.From.UserName);
                Assert.AreEqual(languageCode, callbackQuery.From.LanguageCode);

                //MessageInfo field
                Assert.AreEqual(messageId, callbackQuery.Message.MessageId);
                Assert.AreEqual(date, callbackQuery.Message.DateUnix);
                Assert.AreEqual(chatId, callbackQuery.Message.Chat.Id);
                Assert.AreEqual(chatType, callbackQuery.Message.Chat.Type);

                //CallbackQueryInfo field
                Assert.AreEqual(idСallback, callbackQuery.Id);
                Assert.AreEqual(inlineMessageId, callbackQuery.InlineMessageId);
                Assert.AreEqual(chatInstance, callbackQuery.ChatInstance);
                Assert.AreEqual(data, callbackQuery.Data);
                Assert.AreEqual(gameShortName, callbackQuery.GameShortName);
            });
        }
Esempio n. 2
0
        private static void ParseCommandInCallbackQuery(CallbackQueryInfo callbackQuery)
        {
            if (callbackQuery.Data.Equals("/getId"))
            {
                var chatId = callbackQuery.Message.Chat.Id;
                mClient.SendMessage(chatId, "This chat id is " + chatId);
            }

            if (callbackQuery.Data.Equals("/getLogo"))
            {
                mClient.SendPhoto(callbackQuery.Message.Chat.Id, new ExistingFile
                {
                    Url = "https://raw.githubusercontent.com/themehrdad/NetTelebot/master/Images/Logo/logo-100.png"
                });
            }
        }