Exemple #1
0
        public async Task Greetings(IDialogContext context, LuisResult result)
        {
            string    nameUser = context.Activity.From.Name;
            AdaClient client   = new AdaClient()
            {
                WebAppUrl = $"{ ConfigurationManager.AppSettings["WebAppUrl"] }"
            };
            Activity replyToConversation;
            string   message;

            if (nameUser != null)
            {
                string[] firstNameUser = nameUser.Split(' ');
                message = $"{Dialog.Greeting.Spintax()} {firstNameUser[0]}";
            }
            else
            {
                message = $"{Dialog.Greeting.Spintax()}";
            }
            await context.PostAsync(message);

            CreateDialog createCarousel = new CreateDialog();
            var          idUser         = context.Activity.From.Id;
            var          accessAllow    = await client.GetAuthorizationFacebook(idUser);

            if (accessAllow == "true")
            {
                replyToConversation = createCarousel.CarouselPossibilities(context);
            }
            else
            {
                replyToConversation = createCarousel.CarouselPossibilitiesNotAllowed(context);
            }
            await context.PostAsync(replyToConversation);

            context.Done <object>(null);
        }
Exemple #2
0
        protected override async Task MessageReceived(IDialogContext context, IAwaitable <IMessageActivity> item)
        {
            AdaClient client = new AdaClient()
            {
                WebAppUrl = $"{ ConfigurationManager.AppSettings["WebAppUrl"] }"
            };
            var idUser = context.Activity.From.Id;

            var accessAllow = await client.GetAuthorizationFacebook(idUser);

            if (accessAllow == "true")
            {
                await context.Forward(new AdaDialog(
                                          new LuisService(new LuisModelAttribute(
                                                              ConfigurationManager.AppSettings["ModelId"],
                                                              ConfigurationManager.AppSettings["SubscriptionKey"]))),
                                      BasicCallback, context.Activity as Activity, CancellationToken.None);
            }
            else
            {
                var message = (Activity)await item;
                await base.MessageReceived(context, item);
            }
        }
Exemple #3
0
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <HttpResponseMessage> Post([FromBody] Activity activity)
        {
            bool answer = true;

            AdaClient client = new AdaClient()
            {
                WebAppUrl = $"{ ConfigurationManager.AppSettings["WebAppUrl"] }"
            };

            string accessAllow;
            string idUser;

            if (activity.ServiceUrl == "https://facebook.botframework.com")
            {
                idUser      = activity.From.Id;
                accessAllow = await client.CheckIdFacebook(idUser);

                if (accessAllow == "false")
                {
                    UserIndentifiedDto userIndentified = new UserIndentifiedDto();
                    string             nameUser        = activity.From.Name + " ";
                    string[]           nameUserSplit;
                    nameUserSplit = nameUser.Split(' ');

                    userIndentified.IdFacebook = idUser;
                    userIndentified.Firtsname  = nameUserSplit[0];
                    var    nbNameSplit = nameUserSplit.Count();
                    string lastName    = "";
                    for (int i = 1; i < nbNameSplit; i++)
                    {
                        lastName += nameUserSplit[i] + " ";
                    }
                    userIndentified.LastName      = lastName;
                    userIndentified.authorization = false;

                    var respond = await client.AddNewUserIndentified(userIndentified);
                }
            }

            if (activity.ServiceUrl == "https://slack.botframework.com" && !activity.Text.Contains("ada"))
            {
                answer = false;
            }

            if (activity.Type == ActivityTypes.Message)
            {
                if (activity.Text == "RegisterApp")
                {
                    // persist this information
                    serviceUrl   = activity.ServiceUrl;
                    from         = activity.From;
                    botAccount   = activity.Recipient;
                    conversation = activity.Conversation;

                    ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
                    await connector.Conversations.ReplyToActivityAsync(activity.CreateReply("registered"));

                    return(new HttpResponseMessage(System.Net.HttpStatusCode.Accepted));
                }
                if (activity.Text == "Picture from UWP")
                {
                    answer = false;
                    activity.Conversation.Id = activity.Name;
                    ConnectorClient connector = new ConnectorClient(new Uri(activity.Name));
                    await connector.Conversations.SendToConversationAsync((Activity)activity.ChannelData);
                }

                if (activity.Text == "Passage person from UWP")
                {
                    answer = false;
                    activity.Conversation.Id = Convert.ToString(activity.ChannelData);
                    ConnectorClient connector = new ConnectorClient(new Uri("https://facebook.botframework.com"));
                    await connector.Conversations.SendToConversationAsync((Activity)activity.ChannelData);
                }

                if (activity.Attachments?.Count() >= 1)
                {
                    if (activity.Attachments[0].ContentType == "image/png" || activity.Attachments[0].ContentType == "image/jpeg" || activity.Attachments[0].ContentType == "image/jpg")
                    {
                        StringConstructor stringConstructor = new StringConstructor();
                        try
                        {
                            await stringConstructor.PictureAnalyseAsync(activity);

                            answer = false;
                        }
                        catch (ClientException e)
                        {
                            Debug.WriteLine(e.Error.Message);
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine(e.Message);
                        }
                    }
                }

                if (answer)
                {
                    idUser      = activity.From.Id;
                    accessAllow = await client.GetAuthorizationFacebook(idUser);

                    if (accessAllow == "false")
                    {
                        await Conversation.SendAsync(activity, () => new NotAllowedAdaDialog(
                                                         new LuisService(new LuisModelAttribute(
                                                                             ConfigurationManager.AppSettings["ModelId"],
                                                                             ConfigurationManager.AppSettings["SubscriptionKey"]))));
                    }
                    else
                    {
                        await Conversation.SendAsync(activity, () => new AdaDialog(
                                                         new LuisService(new LuisModelAttribute(
                                                                             ConfigurationManager.AppSettings["ModelId"],
                                                                             ConfigurationManager.AppSettings["SubscriptionKey"]))));
                    }
                }
            }
            else
            {
                //add code to handle errors, or non-messaging activities
            }

            return(new HttpResponseMessage(System.Net.HttpStatusCode.Accepted));
        }