Ejemplo n.º 1
0
        internal static void Main(string[] args)
        {
            // initialize self
            L.R(Console.Out);
            L.D(Debugger.IsAttached);
            UTF8 = new UTF8Encoding(false);
            Console.CancelKeyPress += Console_CancelKeyPress;

            // init sockets
            L.W("ADA", "Initializing ADA Socket manager");
            SocketManager = new AdaSocketManager();
            SocketManager.Initialize();
            L.W("ADA", "ADA Socket manager initialized");

            // init discord
            L.W("ADA", "Initializing ADA Discord module");
            AdaClient = new AdaClient();
            AdaClient.Initialize();
            L.W("ADA", "ADA Discord module initialized");

            // load plugins
            L.W("ADA", "Loading ADA Plugins");
            PluginManager = new AdaPluginManager();
            PluginManager.LoadAssemblies();
            L.W("ADA", "ADA Plugins loaded");

            // init config
            L.W("ADA", "Initializing ADA Config module");
            ConfigManager = new AdaConfigManager();
            ConfigManager.Initialize();
            L.W("ADA", "ADA Config module initialized");

            // init plugins
            L.W("ADA", "Initializing ADA Plugins");
            PluginManager.Initialize();
            L.W("ADA", "ADA Plugins Initialized");

            // init commands
            L.W("ADA", "Initializing ADA Command module");
            CommandManager = new AdaCommandManager();
            CommandManager.Initialize();
            L.W("ADA", "ADA Command module initialized");

            // run
            L.W("ADA", "ADA is now running");
            KeepRunning = true;
            while (KeepRunning)
            {
            }

            // some shutdown signal and subsequent shutdown
            L.W("ADA", "Caught exit signal");
            AdaClient.Deinitialize();
            L.W("ADA", "Disposing logger");
            L.Q();
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
0
        public async Task <PersonDto[]> MakeRecognition()
        {
            AdaClient client = new AdaClient()
            {
                WebAppUrl = AppConfig.WebUri
            };

            using (var stream = new InMemoryRandomAccessStream())
            {
                await WebcamService.MediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);

                await stream.FlushAsync();

                stream.Seek(0);

                try
                {
                    PersonDto[] persons = await DataService.RecognizePersonsAsync(stream.AsStreamForRead());

                    // Logs results on screen
                    if (persons != null)
                    {
                        LogHelper.LogPersons(persons);

                        foreach (PersonDto person in persons)
                        {
                            Guid faceApi       = person.PersonId;
                            var  personMessage = await client.GetPersonByFaceId(faceApi);

                            if (personMessage != null)
                            {
                                List <MessageDto> messages = await client.GetMessageByReceiver(personMessage.PersonId);

                                foreach (MessageDto message in messages)
                                {
                                    if (message.From != null)
                                    {
                                        await TtsService.SayAsync("Bonjour" + person.FirstName + "Tu as un nouveau message de la part de " + message.From);
                                    }
                                    else
                                    {
                                        await TtsService.SayAsync("Bonjour" + person.FirstName + "Tu as un nouveau message ");
                                    }
                                    await TtsService.SayAsync(message.Contenu);

                                    message.IsRead = true;
                                    message.Read   = DateTime.Now;

                                    await client.PutMessage(message);
                                }

                                List <IndicatePassageDto> indicatePassages = await client.GetIndicatePassageByPerson(personMessage.PersonId);

                                foreach (IndicatePassageDto indicatePassage in indicatePassages)
                                {
                                    // need to send message to the person on facebook
                                    try
                                    {
                                        var activity = new Activity
                                        {
                                            From        = new ChannelAccount("Jean"),
                                            Type        = ActivityTypes.Message,
                                            Text        = "Passage person from UWP",
                                            ChannelData = indicatePassage.Firtsname,
                                            Name        = "Passage person from UWP"
                                        };

                                        //await _client.Conversations.PostActivityAsync(indicatePassage.IdFacebookConversation, activity);
                                    }
                                    catch (HttpRequestException)
                                    {
                                        //Impossible to take picture
                                    }

                                    indicatePassage.IsSend = true;
                                    await client.PutIndicatePassage(indicatePassage);
                                }
                            }
                        }
                    }
                    if (persons == null)
                    {
                        LogHelper.Log("Ho, j'ai cru voir quelqu'un :'(");
                    }

                    return(persons);
                }
                catch (HttpRequestException)
                {
                    await TtsService.SayAsync("Veuillez m'excuser je ne suis pas disponible pour le moment. Veuillez ré-éssayer dans quelque secondes");

                    await Task.Delay(5000);

                    return(null);
                }
            }
        }
Ejemplo n.º 6
0
        protected override async Task OnLoadedAsync()
        {
            await Task.Run(() => { while (!_isDirectLineInitialized)
                                   {
                                   }
                           });

            connection.OnMessage += Connection_OnMessage;

            // Registers to messenger for on screen log messages
            Messenger.Default.Register <LogMessage>(this, async e => await DispatcherHelper.RunAsync(() => LogMessage += e.Message));

            // Begins to listening "hello ada"
            await VoiceInterface.ListeningHelloAda();

            // Registers to messenger to catch messages when a speech recognition result
            // was generated
            Messenger.Default.Register <SpeechResultGeneratedMessage>(this, async e =>
            {
                if (e.Result.Constraint.Tag == "constraint_hello_ada")
                {
                    if (VoiceInterface != null)
                    {
                        await VoiceInterface.StopListening();
                    }

                    LogHelper.Log("Message reçu ;)");
                    LogHelper.Log("Je suis à toi dans un instant");
                    await TtsService.SayAsync("Message reçu, je suis à toi dans un instant");

                    PersonDto person = null;

                    if (WebcamService.FaceDetectionEffect != null)
                    {
                        await WebcamService.StopFaceDetectionAsync();
                        person = (await MakeRecognition())?.FirstOrDefault();
                    }

                    if (person != null)
                    {
                        PersonUpdateDto updateDto = new PersonUpdateDto
                        {
                            PersonId      = person.PersonId,
                            RecognitionId = person.RecognitionId
                        };

                        await VoiceInterface.SayHelloAsync(person);

                        // Update person's name
                        if (person.FirstName == null)
                        {
                            string answer = await VoiceInterface.AskIdentified();

                            if (answer != "non")
                            {
                                string name = await VoiceInterface.AskNameAsync();

                                if (name == null)
                                {
                                    return;
                                }

                                updateDto.FirstName = name;
                                person.FirstName    = name;

                                AdaClient client = new AdaClient()
                                {
                                    WebAppUrl = AppConfig.WebUri
                                };

                                await client.PutPerson(updateDto);
                            }
                        }
                    }
                    else
                    {
                        await TtsService.SayAsync("Bonjour");
                    }
                    await DispatcherHelper.RunAsync(async() => { await SolicitExecute(); });
                }
            });

            //// Prepares capture element to camera feed and load camera
            CaptureElement = new CaptureElement();
            await CameraLoadExecute();
        }