public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            var message = await argument;

            if (_client == null)
            {
                _client = new WitConversation <MessageContext>("TIFXIBFNFSADNG56RNDJQ7V6VOP5Q554", message.From.Id, null, DoMerge, DoSay, DoAction, DoStop);
            }

            if (message.Text == "Сбросить")
            {
                PromptDialog.Confirm(
                    context,
                    AfterResetAsync,
                    "Уверены что хотите сбросить счетчик?",
                    "Не понял!");
            }
            else if (message.Text == "Форма")
            {
                context.Call(JsonDialog.MakeJsonRootDialog(), this.ResumeAfterEnhanceDialog);
            }
            else
            {
                Task <bool> t = _client.SendMessageAsync(message.Text);
                t.Wait();

                await context.PostAsync($"{Context.Count++}: {Context.Message}");

                context.Wait(MessageReceivedAsync);
            }
        }
Beispiel #2
0
        public async Task<IHttpActionResult> PostMessage(ORBotChatMessage context)
        {

            var _dict = new Dictionary<string, object>();
            if (!string.IsNullOrWhiteSpace(context.Categoria))
                _dict.Add("categoria", context.Categoria);

            if (!string.IsNullOrWhiteSpace(context.Orgaos))
                _dict.Add("orgaos", context.Orgaos);

            if (!string.IsNullOrWhiteSpace(context.Orgao))
                _dict.Add("orgao", context.Orgao);

            if (!string.IsNullOrWhiteSpace(context.Problema))
                _dict.Add("problema", context.Problema);

            if (!string.IsNullOrWhiteSpace(context.Conversation))
                _dict.Add("conversation", context.Conversation);
            else
            {
                _dict.Add("conversation", Guid.NewGuid().ToString());
            }
            if (!string.IsNullOrWhiteSpace(context.Message))
                _dict.Add("message", context.Message);


            //_chatService = GetCachedData(_dict["conversation"].ToString(), new DateTimeOffset(DateTime.Now.AddDays(1d)));

            //var conversation = await _chatService.GetMessageAsync(_dict);

            //return Ok(new
            //{
            //    Status = 200,
            //    Context = conversation
            //});

            var _session = _dict["conversation"].ToString();

            _client = new WitConversation<Dictionary<string, object>>(ConfigConstants.WIT_ACCESS_TOKEN, _session, _dict, Merge , Say, DoAction, Stop);

            await _client.SendMessageAsync(context.Message);

            //_context.Add("orgao", "Ministério da Saúde");

            //await _client.SendMessageAsync(string.Empty);

            //_context.Add("problem", "falta de remédio");

            //await _client.SendMessageAsync(string.Empty);

            return Ok(new
            {
                Status = 200,
                Context = _dict
            });
        }
Beispiel #3
0
        public void WitConversation_Conversation_Test()
        {
            var client = new WitConversation <DemoContext>(Properties.Settings.Default.WitToken, conversationId, null,
                                                           doMerge, doSay, doAction, doStop);
            Task <bool> t = client.SendMessageAsync("hello");

            t.Wait();

            Assert.IsTrue(t.Result && didMerge && didStop);
        }
        public async Task <Dictionary <string, object> > GetMessageAsync(Dictionary <string, object> context)
        {
            _conversationId  = context.ContainsKey("conversation") ? context["conversation"].ToString() : Guid.NewGuid().ToString();
            _witConversation = new WitConversation <Dictionary <string, object> >(_token, _conversationId, context, DoMerge, DoSay, DoAction, DoStop);

            var message = context["message"].ToString();

            context.Remove("message");
            context.Remove("conversation");

            await _witConversation.SendMessageAsync(message);

            return(context);
        }
        public async Task DeveConversarComOBotCorretamente()
        {
            var _session = Guid.NewGuid().ToString();
            var context  = new Dictionary <string, object>();

            _client = new WitConversation <Dictionary <string, object> >(WIT_TOKEN, _session, context, Merge, Say, DoAction, Stop);

            // enviar a primeira mensagem
            //context.Add("category", "O meu problema é transporte");

            await _client.SendMessageAsync("O meu problema é saude!");

            context.Add("orgao", "Ministério da Saúde");

            await _client.SendMessageAsync(string.Empty);

            context.Add("problem", "falta de remédio");

            await _client.SendMessageAsync(string.Empty);

            Assert.IsTrue(true);

            return;
        }