Beispiel #1
0
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <HttpResponseMessage> Post([FromBody] Activity activity)
        {
            if (activity.Type == ActivityTypes.Message)
            {
                string notificationData = string.Empty;
                // Notitication is sent
                if (NotificationsManager.TryGetNotificationData(activity, out notificationData))
                {
                    // A notification related backchannel message was detected
                    Notification notification = Notification.FromJsonString(notificationData);

                    var dialogManager = DialogManager.Dialogs.GetInstance();

                    //notification is already the active dialog
                    if (dialogManager.IsActiveDialog(activity.Conversation.Id))
                    {
                        await Notifications.NotificationsManager.SendNotificationAsync(notification);
                    }
                    else
                    {
                        //if there is not active dialog
                        if (dialogManager.IsFirstDialog(activity.Conversation.Id) && !dialogManager.ActiveDialogExist())
                        {
                            await Notifications.NotificationsManager.SendNotificationAsync(notification);
                        }
                        else
                        {
                            if (notification.Priority < NotificationPriorityOptions.High)
                            {
                                dialogManager.StackDialog(activity, notification);
                                var responseMessage = new HttpResponseMessage(HttpStatusCode.OK);
                                return(responseMessage);
                            }
                            else
                            {
                                var pausedDialog = dialogManager.PauseActiveDialog();
                                notification.Message = $"High Prio Message: {notification.Message}";
                                await Notifications.NotificationsManager.SendNotificationAsync(notification);

                                dialogManager.UnPauseActiveDialog(pausedDialog);
                            }
                        }
                    }
                }
                // Normal message is sent
                else
                {
                    // Normal Message, just sent it.
                    //Save sending party to Azure Table
                    MessageRouting.MessageRouterManager.Instance.StoreParties(activity);
                    await Conversation.SendAsync(activity, () => new RootDialog());
                }
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }