Exemplo n.º 1
0
    public static async Task HandleScheduleCommand(IDialogContext context, Activity activity, string[] keywords)
    {
        JObject ctx = activity.Value as JObject;

        // Check if this is a button press or a text command.
        if (ctx != null)
        {
            JObject  scheduleRequest = JObject.Parse((string)ctx["body"]);
            DateTime scheduleDate    = DateTime.Parse((string)scheduleRequest["date"]);

            // make call to the Microsoft Graph to schedule the interview

            await MessageHelpers.SendMessage(context, $"Interview scheduled for position {scheduleRequest["reqId"]} with {scheduleRequest["name"]} on {scheduleDate.ToShortDateString()}");
        }
        else if (keywords.Length == 3)
        {
            string name  = string.Join(" ", keywords.Take(2).ToArray());
            string reqId = keywords[2];

            // Takes 3 parameters: first name, last name, and then req ID
            await SendScheduleInterviewMessage(context, name, reqId);
        }
        else
        {
            await MessageHelpers.SendMessage(context, MessageHelpers.CreateHelpMessage("I'm sorry, I did not understand you :("));
        }
    }
Exemplo n.º 2
0
        public void Send()
        {
            try
            {
                using (var db = new AppDbContext())
                {
                    var unsentMsgs = db.Messages.Where(x => (x.Status == MessageStatus.Pending || x.Status == MessageStatus.Failed)).ToList();

                    foreach (var msg in unsentMsgs)
                    {
                        MessageHelpers.SendMessage(msg.Id);
                    }
                }
            }
            catch (Exception) { }
        }
Exemplo n.º 3
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
        {
            var activity = await result as Activity;

            // Strip out all mentions.  As all channel messages to a bot must @mention the bot itself, you must strip out the bot name at minimum.
            // This uses the extension SDK function GetTextWithoutMentions() to strip out ALL mentions
            var text = activity.GetTextWithoutMentions();

            if (text == null && (activity.Attachments != null && activity.Attachments.Count == 0))
            {
                // if the activity is not a system event, and it does not have text or attachment, treat it as a SubmitAction
                //await HandleSubmitAction(context, activity);
            }
            else
            {
                #region Receive file
                // If a file was sent, echo back its name try to read it.
                if (activity.Attachments != null && activity.Attachments.Count > 0)
                {
                    foreach (var attachment in activity.Attachments)
                    {
                        if (attachment.ContentType == FileDownloadInfo.ContentType)
                        {
                            await context.PostAsync($"Received a file named {attachment.Name}");

                            await FileHelpers.ProcessAttachment(attachment, context);
                        }
                    }
                }
                #endregion

                if (!String.IsNullOrEmpty(text))
                {
                    // Check for suppported commands
                    // This simple text parsing assumes the command is the first two tokens,
                    // and parameters are the remainder.
                    var split = text.Split(' ');
                    // The user is asking for one of the supported commands.
                    if (split.Length >= 2)
                    {
                        var cmd      = split[0].ToLower();
                        var keywords = split.Skip(1).ToArray();

                        #region Commands

                        if (cmd.Contains("resume"))
                        {
                            // Return "resume file" for the given candidate name.
                            await HandleResumeCommand(context, keywords);
                        }
                        else if (cmd.Contains("schedule"))
                        {
                            await CommandHandlers.HandleScheduleCommand(context, activity, keywords);
                        }
                        else if (cmd.Contains("open"))
                        {
                            await CommandHandlers.HandleOpenCommand(context);
                        }
                        else if (cmd.Contains("candidate"))
                        {
                            await CommandHandlers.HandleCandidateCommand(context, activity, keywords);
                        }
                        else if (cmd.Contains("new"))
                        {
                            await CommandHandlers.HandleNewCommand(context);
                        }
                        else if (cmd.Contains("assign"))
                        {
                            await CommandHandlers.HandleAssignCommand(context, split);
                        }

                        #endregion
                    }
                    else if (text.Contains("help"))
                    {
                        // Respond with standard help message.
                        await MessageHelpers.SendMessage(context, MessageHelpers.CreateHelpMessage("Sure, I can provide help info about me."));
                    }
                    else if (text.Contains("welcome") || text.Contains("hello") || text.Contains("hi"))
                    {
                        await MessageHelpers.SendMessage(context, MessageHelpers.CreateHelpMessage("## Welcome to the Contoso Talent Management app"));
                    }
                    else
                    // Don't know what to say so this is the generic handling here.
                    {
                        await MessageHelpers.SendMessage(context, MessageHelpers.CreateHelpMessage("I'm sorry, I did not understand you :("));
                    }
                }
            }
            context.Wait(MessageReceivedAsync);
        }