Esempio n. 1
0
        public async Task <string> PostAsync(MessageViewModel message)
        {
            var retorno = _watsonBot.SendMessage(message.Content, message.From);


            foreach (Generic resp in retorno.output.generic)
            {
                switch (resp.response_type)
                {
                case "text":

                    var messageObj = new
                    {
                        id      = Guid.NewGuid(),
                        to      = message.From,
                        type    = "text/plain",
                        content = resp.text
                    };
                    await _blipService.SendMessageAsync(messageObj);

                    break;

                case "option":
                    string content = resp.title;

                    content += "\n";

                    foreach (Option opt in resp.options)
                    {
                        content += opt.label + " - " + opt.value.input.text + "\n";
                    }

                    var messageObjNew = new
                    {
                        id   = Guid.NewGuid(),
                        to   = message.From,
                        type = "text/plain",
                        content
                    };

                    await _blipService.SendMessageAsync(messageObjNew);



                    break;
                }
            }



            return("");
        }
Esempio n. 2
0
        private async Task SendMessageBlip(MessageViewModel message, ResponseModel retornoWatson)
        {
            MessageModel messageModel = null;

            foreach (GenericModel resp in retornoWatson.Output.Generic)
            {
                switch (resp.Response_Type)
                {
                case "text":

                    messageModel = new MessageModel
                    {
                        Id      = Guid.NewGuid(),
                        To      = message.From,
                        Type    = "text/plain",
                        Content = resp.Text
                    };

                    break;

                case "option":
                    string content = resp.Title;

                    content += "\n";

                    foreach (OptionModel opt in resp.Options)
                    {
                        content += opt.Label + "\n";
                    }

                    messageModel = new MessageModel
                    {
                        Id      = Guid.NewGuid(),
                        To      = message.From,
                        Type    = "text/plain",
                        Content = content
                    };

                    break;
                }
                if (messageModel != null)
                {
                    await _blipService.SendMessageAsync(messageModel);
                }
            }
        }