Beispiel #1
0
        private List <KikMessagesSendDataObject> BuildResponses(ExecutionResult result, string chatId, string chatName)
        {
            List <KikMessagesSendDataObject> batchesToSend = new List <KikMessagesSendDataObject>();

            var keyboard = new KikKeyboardDataObject();

            keyboard.type      = "suggested";
            keyboard.responses = new List <KikKeyboardKeyDataObject>();

            result.OptionsToShow.ForEach(a =>
            {
                keyboard.responses.Add(new KikKeyboardKeyDataObject
                {
                    body = a,
                    type = "text"
                });
            });

            var batchedMessages = result.MessagesToShow.Batch(5);

            batchedMessages.ForEach(batch =>
            {
                var dto      = new KikMessagesSendDataObject();
                dto.messages = new List <KikGenericSendMessageDataObject>();

                batch.ForEach(a =>
                {
                    if (!string.IsNullOrEmpty(a.ImageUrl))
                    {
                        var messageDto       = new KikPictureMessageDataObject();
                        messageDto.chatId    = chatId;
                        messageDto.to        = chatName;
                        messageDto.type      = "picture";
                        messageDto.picUrl    = a.ImageUrl;
                        messageDto.keyboards = new List <KikKeyboardDataObject> {
                            keyboard
                        };
                        dto.messages.Add(messageDto);
                    }
                    else
                    {
                        var formattedMessage = a.Message.Replace("\r", "");
                        var messageDto       = new KikMessageSendWithKeyboardDataObject();
                        messageDto.body      = formattedMessage;
                        messageDto.chatId    = chatId;
                        messageDto.to        = chatName;
                        messageDto.type      = "text";
                        messageDto.keyboards = new List <KikKeyboardDataObject> {
                            keyboard
                        };
                        dto.messages.Add(messageDto);
                    }
                });
                batchesToSend.Add(dto);
            });

            return(batchesToSend);
        }
 public static async Task SendMessageAsync(KikHttp kikHttp, KikMessagesSendDataObject message)
 {
     await kikHttp.PostRequestAsync("message", message);
 }