Example #1
0
        public override async Task Render(MessageResult message)
        {
            Bitmap bmp = new Bitmap(800, 600);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.FillRectangle(Brushes.White, 0, 0, bmp.Width, bmp.Height);

                g.DrawString("Test Image", new Font("Arial", 24, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Black, new PointF(50, 50));
            }

            await this.Device.SetAction(Telegram.Bot.Types.Enums.ChatAction.UploadPhoto);

            ButtonForm btn = new ButtonForm();

            //btn.AddButtonRow(new ButtonBase("Zum Testformular 1", CallbackData.Create("navigate", "testform1")), new ButtonBase("Zum Testformular 1", CallbackData.Create("navigate", "testform1")));

            btn.AddButtonRow(new ButtonBase("Information Prompt", CallbackData.Create("navigate", "alert")));

            btn.AddButtonRow(new ButtonBase("Confirmation Prompt with event", CallbackData.Create("navigate", "confirm")));

            btn.AddButtonRow(new ButtonBase("Request Prompt", CallbackData.Create("navigate", "prompt")));


            await this.Device.SendPhoto(bmp, "Test", "", btn);
        }
Example #2
0
        public async Task Handle(Query query)
        {
            if (query?.Data == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            CallbackData data;
            var          callbackDataType = query.Data.Split(CallbackData.SEPARATOR).Last();

            if (int.Parse(callbackDataType) == (int)CallbackDataType.GetCallbackData)
            {
                data = CallbackData.Create <GetCallbackData>(query.Data);
            }
            else if (int.Parse(callbackDataType) == (int)CallbackDataType.SendCallbackData)
            {
                data = CallbackData.Create <SendCallbackData>(query.Data);
            }
            else if (int.Parse(callbackDataType) == (int)CallbackDataType.SettingsCallbackData)
            {
                data = CallbackData.Create <SettingsCallbackData>(query.Data);
            }
            else if (int.Parse(callbackDataType) == (int)CallbackDataType.GeneralCallbackData)
            {
                data = CallbackData.Create <GeneralCallbackData>(query.Data);
            }
            else
            {
                return;
            }

            Exception exception = null;

            try
            {
                var resultInvoke = await RuleInvokeAction(_authRule, data, query);

                if (resultInvoke)
                {
                    return;
                }

                var service = Methods.SearchServiceByUserId(query.From);
                var rules   = service.FullUserAccess
                    ? _fullAccessRules
                    : _notifyAccessRules;
                foreach (var rule in rules)
                {
                    await RuleInvokeAction(rule, data, query, service);
                }
            }
            catch (ServiceNotFoundException ex)
            {
                exception = ex;
                await _botActions.WrongCredentialsMessage(query.From);
            }
            catch (DbDataStoreException ex)
            {
                exception = ex;
                await _botActions.WrongCredentialsMessage(query.From);
            }
            catch (AuthorizeException ex)
            {
                exception = ex;
                await _botActions.AuthorizationErrorMessage(query.From);
            }
            catch (TelegramMethodsException ex)
            {
                exception = ex;
            }
            catch (Exception ex)
            {
                exception = ex;
                try
                {
                    await _botActions.ErrorOperation(query.Id);
                }
                catch { }
            }
            finally
            {
                if (exception != null)
                {
                    LogMaker.Log(Logger, exception,
                                 $"An exception has been thrown in processing CallbackQuery with data: {query.Data}");
                }
            }
        }