Esempio n. 1
0
        async Task SendMessage(IDialogContext context, string message, string image, string original, string intent)
        {
            if (string.IsNullOrEmpty(message))
            {
                return;
            }

            IMessageActivity msg = context.MakeMessage();

            msg.Text = message;
            if (!string.IsNullOrEmpty(image))
            {
                msg.Attachments = new List <Attachment>();
                msg.Attachments.Add(new Attachment {
                    ContentType = "image/png", ContentUrl = image
                });
            }

            try
            {
                if (!string.IsNullOrEmpty(intent))
                {
                    StorageLogger.LogData(new DataLog {
                        Question = original, Answer = message, Intent = intent, User = context.MakeMessage().Recipient.Name
                    });
                }
            }
            catch { }

            await context.PostAsync(msg);
        }
Esempio n. 2
0
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <HttpResponseMessage> Post([FromBody] Activity activity)
        {
            ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));

            try
            {
                if (activity.GetActivityType() == ActivityTypes.Message)
                {
                    if (!string.IsNullOrEmpty(activity.Text) && !m_doNotProcess.Contains(activity.Text.Trim().ToLower()))
                    {
                        LanguageManager lang;
                        if (IsLanguageCommand(activity.Text, out lang))
                        {
                            StateClient state = activity.GetStateClient();
                            BotData     data  = state.BotState.GetUserData(activity.ChannelId, activity.From.Id);
                            data.SetProperty <string>(LanguageManager.QUERY_LANGUAGE, lang.Language);
                            state.BotState.SetUserData(activity.ChannelId, activity.From.Id, data);
                            await connector.Conversations.ReplyToActivityAsync(activity.CreateReply(lang.LangChange));
                        }
                        else
                        {
                            await Conversation.SendAsync(activity, MakeRoot);
                        }
                    }
                    else                     // is it an emoji or attachment?
                    {
                        await connector.Conversations.ReplyToActivityAsync(activity.CreateReply(":)"));
                    }
                }
                else
                {
                    await connector.Conversations.ReplyToActivityAsync(HandleSystemMessage(activity));
                }
            }
            catch (Exception ex)
            {
                try
                {
                    StorageLogger.LogError(new ErrorLog(ex)
                    {
                        Question = activity.Text, User = activity.From.Name
                    });
                }
                catch { }

                Activity msg = activity.CreateReply("BOT ERROR! Nooooooooooooooo");
                msg.Attachments = new List <Attachment>();
                msg.Attachments.Add(new Attachment {
                    ContentType = "image/png", ContentUrl = ImageHelper.GetVader()
                });
                await connector.Conversations.ReplyToActivityAsync(msg);
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Esempio n. 3
0
        public async Task Start(string readNodesPath, string readLinksPath, int numberOfLinkChannels)
        {
            await InfoLogger.LogInformation($"Starting RoutingAndSpectrumAllocation\n");

            await InfoLogger.LogInformation($"Nodes Path: \"{readNodesPath}\"\n");

            await InfoLogger.LogInformation($"Links Path: \"{readLinksPath}\"\n");

            Graph graph = ReadGraph(readNodesPath, readLinksPath);

            await StorageLogger.WriteLog("graph", graph);

            List <Demand> demands = GetDemands(graph);

            await StorageLogger.WriteLog("demands", demands);

            await ApplyRSA(graph, demands, numberOfLinkChannels);
        }
Esempio n. 4
0
        public async Task Restroom(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            if (IsScoreTooLow(context, result))
            {
                await None(context, activity, result);

                return;
            }
            else
            {
                OnSuccess(context);
            }

            LanguageManager lang = await LanguageManager.GetLanguage(context, activity);

            StorageLogger.LogData(new DataLog {
                Question = result.Query, Answer = lang.WhatFloor, Intent = RESTROOM
            });

            var floors = new[] { 2, 3, 4 };

            PromptDialog.Choice(context, RestroomFloorComplete, floors, string.Format(lang.WhatFloor, floors), string.Format(lang.InvalidFloor, floors), 3, PromptStyle.Auto);
        }