Exemple #1
0
 public MessageKeyboardButton GetButton(KeyboardButtonColor color, string label)
 {
     return(new MessageKeyboardButton()
     {
         Color = color,
         Action = new MessageKeyboardButtonAction()
         {
             Label = label,
             Type = KeyboardButtonActionType.Text
         }
     });
 }
Exemple #2
0
        public void KeyboardButtonColorTest()
        {
            // get test
            Assert.That(KeyboardButtonColor.Default.ToString(), Is.EqualTo("default"));
            Assert.That(KeyboardButtonColor.Negative.ToString(), Is.EqualTo("negative"));
            Assert.That(KeyboardButtonColor.Positive.ToString(), Is.EqualTo("positive"));
            Assert.That(KeyboardButtonColor.Primary.ToString(), Is.EqualTo("primary"));

            // parse test
            Assert.That(KeyboardButtonColor.FromJsonString("default"), Is.EqualTo(KeyboardButtonColor.Default));
            Assert.That(KeyboardButtonColor.FromJsonString("negative"), Is.EqualTo(KeyboardButtonColor.Negative));
            Assert.That(KeyboardButtonColor.FromJsonString("positive"), Is.EqualTo(KeyboardButtonColor.Positive));
            Assert.That(KeyboardButtonColor.FromJsonString("primary"), Is.EqualTo(KeyboardButtonColor.Primary));
        }
Exemple #3
0
        public void KeyboardButtonColorTest()
        {
            // get test
            Assert.That(actual: KeyboardButtonColor.Default.ToString(), expression: Is.EqualTo(expected: "default"));
            Assert.That(actual: KeyboardButtonColor.Negative.ToString(), expression: Is.EqualTo(expected: "negative"));
            Assert.That(actual: KeyboardButtonColor.Positive.ToString(), expression: Is.EqualTo(expected: "positive"));
            Assert.That(actual: KeyboardButtonColor.Primary.ToString(), expression: Is.EqualTo(expected: "primary"));

            // parse test
            Assert.That(actual: KeyboardButtonColor.FromJsonString(response: "default"), expression: Is.EqualTo(expected: KeyboardButtonColor.Default));
            Assert.That(actual: KeyboardButtonColor.FromJsonString(response: "negative"), expression: Is.EqualTo(expected: KeyboardButtonColor.Negative));
            Assert.That(actual: KeyboardButtonColor.FromJsonString(response: "positive"), expression: Is.EqualTo(expected: KeyboardButtonColor.Positive));
            Assert.That(actual: KeyboardButtonColor.FromJsonString(response: "primary"), expression: Is.EqualTo(expected: KeyboardButtonColor.Primary));
        }
        public MessageKeyboardButton GetButton(Keyboard keyboard, long groupId)
        {
            KeyboardButtonColor color = KeyboardButtonColor.Default;

            switch (Color)
            {
            case ButtonColor.Blue:
                color = KeyboardButtonColor.Primary;
                break;

            case ButtonColor.Green:
                color = KeyboardButtonColor.Positive;
                break;

            case ButtonColor.Red:
                color = KeyboardButtonColor.Negative;
                break;
            }

            var action = new MessageKeyboardButtonAction()
            {
                Label = Label
            };

            switch (_buttonType)
            {
            case CallbackButtonType.Callback:
                action.Type = KeyboardButtonActionType.Callback;
                break;

            case CallbackButtonType.Text:
                action.Type = KeyboardButtonActionType.Text;
                break;
            }

            action.Payload = new KeyboardButtonPayload()
            {
                GroupId    = groupId,
                KeyboardId = keyboard.Id,
                ButtonId   = Id,
                Payload    = Payload
            }.Serialize();

            return(new MessageKeyboardButton()
            {
                Color = color, Action = action
            });
        }
        /// <inheritdoc />
        public IKeyboardBuilder AddButton(string label, string extra, KeyboardButtonColor color = default(KeyboardButtonColor),
                                          string type = null)
        {
            color = color ?? KeyboardButtonColor.Default;
            type  = type ?? _type ?? Button;

            _currentLine.Add(new MessageKeyboardButton
            {
                Color  = color,
                Action = new MessageKeyboardButtonAction
                {
                    Label   = label,
                    Payload = $"{{\"{type}\":\"{extra}\"}}",
                    Type    = KeyboardButtonActionType.Text
                }
            });

            return(this);
        }
 public KeyboardBuilder AddButton(string text, string command, List <string> arguments = null, bool reqContact = false, bool reqLocation = false, KeyboardButtonColor color = default, KeyboardButtonActionType type = null,
                                  string btnHash = null, ulong?btnAppId = null, ulong?btnOwnerId = null)
 {
     if (command != null)
     {
         try
         {
             var pb = new PayloadBuilder(command, arguments);
             _bot.AliasesCommand.Add(text, pb.BuildToModel());
         }catch (Exception)
         {
             //Console.WriteLine($"Алиас {text} уже существует.");
         }
     }
     AddButton(new NucleusKeyboardButton()
     {
         Caption         = text ?? "my button",
         RequestContact  = reqContact,
         RequestLocation = reqLocation,
         Color           = color,
         Type            = type ?? KeyboardButtonActionType.Text,
         Payload         = command != null ? new PayloadBuilder(command, arguments).BuildToModel(): null,
         Hash            = btnHash ?? null,
         AppID           = btnAppId ?? 0,
         OwnerID         = btnOwnerId ?? 0
     });
     return(this);
 }