示例#1
0
        protected override bool ParseIncomingMessage(String json, out IChatSession s, out IIncomingMessage m)
        {
            s = null;
            m = null;
            Update update = JsonConvert.DeserializeObject <Update>(json);

            switch (update.Type)
            {
            case UpdateType.Unknown:
                return(false);

            case UpdateType.Message:
            {
                m = new IncomingMessage(update.Message);
                s = new ChatSession(update.Message.Chat.Id);
                return(true);
            }

            case UpdateType.InlineQuery:
                return(false);

            case UpdateType.ChosenInlineResult:
                return(false);

            case UpdateType.CallbackQuery:
            {
                var message = update.CallbackQuery.Message;
                message.Text = update.CallbackQuery.Data;
                m            = new IncomingMessage(message);
                s            = new ChatSession(message.Chat.Id);
                return(true);
            }

            case UpdateType.EditedMessage:
                return(false);

            case UpdateType.ChannelPost:
                return(false);

            case UpdateType.EditedChannelPost:
                return(false);

            case UpdateType.ShippingQuery:
                return(false);

            case UpdateType.PreCheckoutQuery:
                return(false);

            default:
                return(false);
            }
        }
示例#2
0
        public override async Task SendMessageAsync(IChatSession sess, IOutgoingMessage msg)
        {
            var ss = new ChatSession(sess);

            switch (msg.Type)
            {
            case MsgOutType.Text:
            {
                await _cli.SendTextMessageAsync(ss.GetChatId(), msg.Text);
            }
            break;

            case MsgOutType.Keyboard:
            {
                await _cli.SendTextMessageAsync
                (
                    ss.GetChatId(),
                    msg.Text,
                    ParseMode.Markdown,
                    false, false, 0,
                    GetTelegramKeyboard(msg.Keyboard)
                );
            }
            break;

            case MsgOutType.Photo:
                break;

            case MsgOutType.Wait:
            {
                await _cli.SendTextMessageAsync(ss.GetChatId(), $"Нагадування встановлено");

                break;
            }

            default:
                break;
            }
        }