Example #1
0
 public Conversation(
     IConversationContext context,
     ISpeaker self,
     ISpeaker target,
     Action <ISpeaker, ISpeaker> action
     ) : base(context, self, target)
     => _action = action;
Example #2
0
        private Route PreparePayloadRoute(IConversationContext conversationContext)
        {
            Route payloadRoute = null;
            var   message      = conversationContext?.Entry?.Message?.Message;
            var   payload      = message?.Quick_reply?.Payload;

            if (payload != null)
            {
                payloadRoute = this.serializer.Deserialize <Route>(payload);
                if (payloadRoute?.RouteText != null)
                {
                    conversationContext.Reply = null;
                    conversationContext.Entry.Message.Message.Text = payloadRoute.RouteText;
                    payloadRoute.RouteData = payloadRoute.RouteData ?? new Dictionary <string, object>();
                    if (conversationContext?.Route?.RouteData != null)
                    {
                        foreach (var data in conversationContext.Route.RouteData)
                        {
                            if (!payloadRoute.RouteData.ContainsKey(data.Key))
                            {
                                payloadRoute.RouteData[data.Key] = data.Value;
                            }
                        }
                    }

                    conversationContext.Route = null;
                }
            }

            return(payloadRoute);
        }
Example #3
0
        public async Task <IConversationContext> FetchContextAsync(IConversationContext context)
        {
            var request = new GetItemRequest
            {
                TableName = this.config.BotConversationContextTableName,
                Key       = new Dictionary <string, AttributeValue>()
                {
                    { "Id", new AttributeValue {
                          SS = new List <string> {
                              context.ConnectorType.ToString(), context.Entry.Message.Sender.Id
                          }
                      } }
                }
            };

            var response = await client.GetItemAsync(request);

            AttributeValue contextData = null;

            if (response.IsItemSet && response.Item.TryGetValue("ContextData", out contextData))
            {
                var data = this.serializer.Deserialize <AwsConversationContext>(contextData.S);
                context.Route = data.Route;
                context.Reply = data.Reply;
            }

            return(context);
        }
        public async Task ClearContextAsync(IConversationContext context)
        {
            try
            {
                var azureContext = new AzureConversationContext
                {
                    PartitionKey = context.ConnectorType.ToString(),
                    RowKey       = context.Entry.Message.Sender.Id,
                    ETag         = "*",
                    StateAction  = context.StateAction
                };

                var deleteOperation = TableOperation.Delete(azureContext);
                await this.PrepareTable(this.config.BotConversationContextTableName).ExecuteAsync(deleteOperation);
            }
            catch (StorageException e)
            {
                if (e.RequestInformation.HttpStatusCode == (int)HttpStatusCode.NotFound)
                {
                    return;
                }

                throw;
            }
        }
Example #5
0
        public async Task <Route> FindRouteAsync(IConversationContext conversationContext)
        {
            var text = conversationContext?.Entry?.Message?.Message?.Text;

            //TODO: INlu.Process
            return(null);
        }
 public LuaScriptConversation(
     string path,
     IConversationContext context,
     ISpeaker self,
     ISpeaker target
     ) : base(context, self, target)
     => ScriptPath = path;
Example #7
0
 public ScriptedConversation(IScript script, IConversationContext context, ISpeaker self, ISpeaker target)
 {
     _script = script;
     Context = context;
     Self    = self;
     Target  = target;
 }
Example #8
0
        public IParameterResult GetParameter(string paramValue, IConversationContext context)
        {
            if (string.IsNullOrWhiteSpace(paramValue))
            {
                return(ResultFactory.GetFailure(ParamMessage));
            }

            var error    = Translator.Text("Chat.Parameters.UserParameterValidationError");
            var username = paramValue.Replace(" ", "");

            if (string.IsNullOrEmpty(username))
            {
                return(ResultFactory.GetFailure(error));
            }

            string regex = @"^(\w[\w\s]*)([\\]{1})(\w[\w\s\.\@]*)$";
            Match  m     = Regex.Match(username, regex);

            if (string.IsNullOrEmpty(m.Value))
            {
                return(ResultFactory.GetFailure(error));
            }

            DomainAccessGuard.Session userSession = null;
            if (Sitecore.Security.Accounts.User.Exists(username))
            {
                userSession = AuthenticationWrapper.GetDomainAccessSessions().FirstOrDefault(
                    s => string.Equals(s.UserName, username, StringComparison.OrdinalIgnoreCase));
            }

            return(userSession == null
                ? ResultFactory.GetFailure(error)
                : ResultFactory.GetSuccess(username, userSession));
        }
Example #9
0
        public async Task <Route> FindRouteAsync(IConversationContext conversationContext)
        {
            var audio = conversationContext?.Entry?.Message?.Message?.Attachments?.FirstOrDefault(x => x.Type == Abstractions.Models.Attachments.AttachmentType.audio);

            //TODO: IAsr.Process
            return(null);
        }
Example #10
0
 public FieldUserInventorySpeaker(
     IConversationContext context,
     FieldUser fieldUser,
     int templateID           = 9010000,
     ScriptMessageParam param = (ScriptMessageParam)0
     ) : base(context, templateID, param)
     => _fieldUser = fieldUser;
        public virtual ConversationResponse ProcessUserInput(IConversationContext context)
        {
            if (string.IsNullOrWhiteSpace(context.Result.Query) || context.Result == null)
            {
                return(IntentProvider.GetDefaultResponse(context.AppId));
            }

            // gather data
            var intent         = IntentProvider.GetTopScoringIntent(context);
            var conversation   = context.GetCurrentConversation();
            var isConfident    = context.Result.TopScoringIntent.Score > ApiKeys.LuisIntentConfidenceThreshold;
            var hasValidIntent = intent != null && isConfident;
            var inConversation = conversation != null && !conversation.IsEnded;
            var requestedQuit  = hasValidIntent && intent.KeyName.Equals(context.QuitIntentName);

            // if the user is trying to end or finish a conversation
            if (inConversation && requestedQuit)
            {
                return(EndCurrentConversation(context));
            }

            // continue conversation
            if (inConversation)
            {
                return(HandleCurrentConversation(context));
            }

            // is a user frustrated or is their intention unclear
            var sentimentScore = context.Result.SentimentAnalysis?.score ?? 1;

            return((sentimentScore <= 0.4)
                ? IntentProvider.GetIntent(context.AppId, context.FrustratedIntentName)?.Respond(null, null, null) ?? IntentProvider.GetDefaultResponse(context.AppId)
                : IntentProvider.GetDefaultResponse(context.AppId));
        }
        /// <summary>
        /// tries to determine a value for the requested parameter from a number of possible locations; current response entities, current response, previously provided information (context), or previously provided entities
        /// </summary>
        /// <param name="paramName"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public virtual string SearchUserValues(string paramName, IConversationContext context)
        {
            var c = context.GetCurrentConversation();

            var paramAlignment = new Dictionary <string, string> {
                { "Date", "builtin.datetimeV2.datetime" }
            };

            if (IsParamRequest(paramName, c)) // was the user responding to a specific request
            {
                return(context.Result.Query);
            }

            var entityType    = paramAlignment.ContainsKey(paramName) ? paramAlignment[paramName] : paramName;
            var currentEntity = context.Result?.Entities?.FirstOrDefault(x => x.Type.Equals(entityType))?.Entity;

            if (currentEntity != null) // check the current request entities
            {
                return(currentEntity);
            }

            if (c.Data.ContainsKey(paramName)) // check the context data
            {
                return(c.Data[paramName].DisplayName);
            }

            var initialEntity = c.Result?.Entities?.FirstOrDefault(x => x.Type.Equals(entityType))?.Entity;

            if (initialEntity != null) // check the initial request entities
            {
                return(initialEntity);
            }

            return(string.Empty);
        }
Example #13
0
 public async Task <TextReplyMessage> CreateReplyMessage(IConversationContext conversationContext, IDictionary <string, string> parameters)
 {
     return(new TextReplyMessage
     {
         Text = "What is surname ?"
     });
 }
Example #14
0
 public async virtual Task <ReplyMessage> ExecuteAsync(IConversationContext conversationContext, MyFormReplyCompletionActionData completionActionData)
 {
     return(new ReplyMessage
     {
         Text = "Form completed :)"
     });
 }
Example #15
0
 public async Task <ReplyMessage> ExecuteAsync(IConversationContext context, TextReplyMessage reply)
 {
     return(new ReplyMessage
     {
         Text = reply.Text
     });
 }
Example #16
0
 public virtual async Task InvokeAsync(IConversationContext conversationContext)
 {
     if (this.NextHandler != null)
     {
         await this.NextHandler.InvokeAsync(conversationContext);
     }
 }
Example #17
0
 public FallbackConversation(IConversationContext context, ISpeaker self, ISpeaker target, string script)
 {
     Context = context;
     Self    = self;
     Target  = target;
     _script = script;
 }
Example #18
0
        public override async Task InvokeAsync(IConversationContext conversationContext)
        {
            var userManager = this.userManagerFunc(conversationContext.ConnectorType);

            conversationContext.User = await userManager.GetUserAsync(conversationContext.Entry.Message.Sender.Id);

            await base.InvokeAsync(conversationContext);
        }
Example #19
0
        public async Task Redirect(string routeText, IConversationContext conversationContext)
        {
            conversationContext.Entry.Message.Message.Text        = routeText;
            conversationContext.Entry.Message.Message.Quick_reply = null;
            var handler = await this.handlerManager.CreateAsync(conversationContext);

            await handler.InvokeAsync(conversationContext);
        }
		public ConversationDouble(bool useStrictMocking, IConversationContext context, IConversation userSpecifiedDouble)
		{
			if (context == null)
				throw new ArgumentNullException("context");
			this.context = context;
			strict = useStrictMocking;
			userDouble = userSpecifiedDouble;
		}
Example #21
0
        public override async Task InvokeAsync(IConversationContext conversationContext)
        {
            var replyItem = await this.replyConfiguration.FetchReplyItem(conversationContext);

            conversationContext.Reply = await this.replyFactory.CreateReplyAsync(conversationContext, replyItem);

            await base.InvokeAsync(conversationContext);
        }
Example #22
0
 public BasicConversation(
     IConversationContext context,
     IConversationSpeaker self,
     IConversationSpeaker target,
     Action <IConversationSpeaker, IConversationSpeaker> action
     ) : base(context, self, target)
 {
     _action = action;
 }
Example #23
0
 public ScriptedConversation(
     IConversationContext context,
     IConversationSpeaker self,
     IConversationSpeaker target,
     IScript script
     ) : base(context, self, target)
 {
     _script = script;
 }
Example #24
0
 public FieldPortalSpeaker(
     IConversationContext context,
     FieldPortalTemplate portal,
     IField field
     ) : base(context)
 {
     this.portal = portal;
     this.field  = field;
 }
Example #25
0
 public Speaker(
     IConversationContext context,
     int templateID           = 9010000,
     ScriptMessageParam param = 0
     ) : base(context)
 {
     TemplateID = templateID;
     Param      = param;
 }
Example #26
0
        public IParameterResult GetParameter(string paramValue, IConversationContext context)
        {
            if (string.IsNullOrWhiteSpace(paramValue))
            {
                return(ResultFactory.GetFailure(ParamMessage));
            }

            return(ResultFactory.GetSuccess(paramValue, paramValue));
            //Translator.Text("SearchForm.Parameters.NameValidationError")
        }
Example #27
0
 protected AbstractConversation(
     IConversationContext context,
     IConversationSpeaker self,
     IConversationSpeaker target
     )
 {
     Context = context;
     Self    = self;
     Target  = target;
 }
Example #28
0
 public async Task <ReplyMessage> ExecuteAsync(IConversationContext context, LocationReplyMessage reply)
 {
     return(new ReplyMessage
     {
         Text = reply.Text,
         Quick_replies = new[] { new QuickReply {
                                     Content_type = ContentType.location
                                 } }
     });
 }
Example #29
0
 public AbstractConversation(
     IConversationContext context,
     ISpeaker self,
     ISpeaker target
     )
 {
     Context = context;
     Self    = self;
     Target  = target;
 }
Example #30
0
 public Speaker(
     IConversationContext context,
     int templateID         = 9010000,
     SpeakerParamType param = 0
     )
 {
     Context    = context;
     TemplateID = templateID;
     ParamType  = param;
 }
Example #31
0
 public BasicSpeaker(
     IConversationContext context,
     int templateID = 9010000,
     ConversationSpeakerFlags flags = 0
     )
 {
     Context    = context;
     TemplateID = templateID;
     Flags      = flags;
 }
		public MockContainer()
		{
			Container = new WindsorContainer();
			Dao = MockRepository.GenerateStrictMock<IDao<Software>>();
			Conversation = MockRepository.GenerateStrictMock<IConversation>();
			Context = MockRepository.GenerateStrictMock<IConversationContext>();
			Container.Register(
				Component.For(typeof(IDao<>)).ImplementedBy(typeof(DummyDao<>)),
				Component.For<IDao<Software>>().Instance(Dao),
				Component.For<IConversation>().Instance(Conversation),
				Component.For<IConversationContext>().Instance(Context));
		}