Exemplo n.º 1
0
        public WatsonResponse MessageWithContext(string utterance, string userid)
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: apikey);

            AssistantService service = new AssistantService("2019-02-28", authenticator);

            service.SetServiceUrl(url);

            MessageContextSkills skills = new MessageContextSkills();
            MessageContextSkill  skill  = new MessageContextSkill();

            skill.UserDefined = new Dictionary <string, object>();
            skill.UserDefined.Add("unidade", FUNC.unidade);
            skill.UserDefined.Add("sexo", FUNC.sexo);
            //Test

            skills.Add("main skill", skill);

            var result = service.Message(
                assistantId: assistantId,
                sessionId: sessionId,
                input: new MessageInput()
            {
                Text = utterance
            },
                context: new MessageContext()
            {
                Global = new MessageContextGlobal()
                {
                    System = new MessageContextGlobalSystem()
                    {
                        UserId = userid
                    }
                },
                Skills = skills
            }
                );

            WatsonResponse response = JsonConvert.DeserializeObject <WatsonResponse>(result.Response);

            return(response);

            //Console.WriteLine(result.Response);
        }
Exemplo n.º 2
0
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            WatsonResponse response = this.MessageWithContext(turnContext.Activity.Text, turnContext.Activity.Recipient.Id);

            foreach (Generic resp in response.output.generic)
            {
                switch (resp.response_type)
                {
                case "text":
                    await turnContext.SendActivityAsync(MessageFactory.Text(response.output.generic[0].text), cancellationToken);

                    break;

                case "option":

                    var reply = MessageFactory.Text(resp.title);

                    reply.SuggestedActions = new SuggestedActions();

                    reply.SuggestedActions.Actions = new List <CardAction>();

                    foreach (Option opt in resp.options)
                    {
                        reply.SuggestedActions.Actions.Add(new CardAction()
                        {
                            Title = opt.label, Type = ActionTypes.ImBack, Value = opt.label
                        });
                    }


                    await turnContext.SendActivityAsync(reply, cancellationToken);

                    break;
                }
            }
        }
Exemplo n.º 3
0
        public WatsonResponse Message(string utterance, string userid)
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: apikey);

            AssistantService service = new AssistantService("2019-02-28", authenticator);

            service.SetServiceUrl(url);

            var result = service.Message(
                assistantId: assistantId,
                sessionId: sessionId,
                input: new MessageInput()
            {
                Text = utterance
            }
                );

            WatsonResponse response = JsonConvert.DeserializeObject <WatsonResponse>(result.Response);


            return(response);
            //Console.WriteLine(result.Response);
        }