public AzureBotServiceMessage Publish(ChannelRequest request)
        {
            BearerToken    = (String)request.Channel.Config["bearerToken"];
            ConversationId = GetConversationId();
            string target      = request.Channel.Target;
            string channelType = target.Substring(target.IndexOf('@') + 1);

            AzureBotServiceMessage message = new AzureBotServiceMessage();

            message.From.Id = request.Id;
            message.Text    = $"notify {target}";

            if (channelType?.ToLower() == "slack")
            {
                message.Value = Slack.CreateSlackMessage(request);
            }
            else if (channelType?.ToLower() == "msteams")
            {
                message.Value = Teams.CreateAdaptiveCardMessage(request);
            }
            else
            {
                throw new Exception($"Unknown ChannelType [{channelType}].");
            }

            SendMessage(message);
            return(message);
        }
Ejemplo n.º 2
0
        // ******************************************************************
        // *** Adaptive Card Methods (Not Supported By Teams As Of 4-JUN-2020)
        // ******************************************************************

        public static AdaptiveCard CreateAdaptiveCardMessage(ChannelRequest request)
        {
            AdaptiveCard message = new AdaptiveCard();

            message.Body.Add(new AdaptiveCardBody());
            Signal signal = request.Signal;

            if (!String.IsNullOrEmpty(signal.Name))
            {
                AdaptiveCardBodyItems header = new AdaptiveCardBodyItems();
                header.Weight = "Bolder";
                header.Type   = "TextBlock";
                header.Size   = "Medium";
                header.Text   = signal.Name;
                message.Body[0].Items.Add(header);
            }

            if (!String.IsNullOrEmpty(signal.Description))
            {
                AdaptiveCardBodyItems description = new AdaptiveCardBodyItems();
                description.Text = signal.Description;
                description.Type = "TextBlock";
                description.Size = "Medium";
                message.Body[0].Items.Add(description);
            }

            if (signal.Cues != null)
            {
                int totalCues = signal.Cues.Keys.Count;
                foreach (string cue in signal.Cues.Keys)
                {
                    AdaptiveCard card = CreateAdaptiveCard(request.Id, cue, signal.Cues[cue]);
                    if (totalCues == 1)
                    {
                        // Create Single Cue in Main Body of Message
                        foreach (AdaptiveCardBody body in card.Body)
                        {
                            message.Body.Add(body);
                        }

                        foreach (AdaptiveCardAction action in card.Actions)
                        {
                            message.Actions.Add(action);
                        }
                    }
                    else
                    {
                        // Create Each Cue as an Action.ShowCard Button
                        AdaptiveCardAction action = new AdaptiveCardAction();
                        action.Type  = "Action.ShowCard";
                        action.Title = cue;
                        action.Card  = card;
                        message.Actions.Add(action);
                    }
                }
            }

            return(message);
        }
        public AzureBotServiceMessage Publish(string id, ChannelDbRecord channel, Signal signal)
        {
            ChannelRequest request = new ChannelRequest
            {
                Id      = id,
                Channel = channel,
                Signal  = signal
            };

            return(Publish(request));
        }
Ejemplo n.º 4
0
        public static SlackMessage Publish(string id, ChannelDbRecord channel, Signal signal)
        {
            ChannelRequest request = new ChannelRequest
            {
                Id      = id,
                Channel = channel,
                Signal  = signal
            };

            return(Publish(request));
        }
Ejemplo n.º 5
0
        public static SlackMessage CreateSlackMessage(ChannelRequest request)
        {
            SlackMessage message = new SlackMessage();
            Signal       signal  = request.Signal;

            String webHook = request?.Channel?.Target;

            string mainTitle = $"{signal.Name}\n{signal.Description}";

            if (String.IsNullOrEmpty(signal.Name))
            {
                mainTitle = signal.Description;
            }
            else if (String.IsNullOrEmpty(signal.Description))
            {
                mainTitle = signal.Name;
            }

            if (!String.IsNullOrWhiteSpace(mainTitle))
            {
                message.Text = mainTitle;
            }
            else if (signal.Cues == null)
            {
                message.Text = " ";
            }

            if (signal.IncludeId)
            {
                if (String.IsNullOrWhiteSpace(message.Text))
                {
                    message.Text = $"Id : {request.Id}";
                }
                else
                {
                    message.Text += $"\n(Id : {request.Id})";
                }
            }

            if (signal.Cues != null)
            {
                foreach (string key in signal.Cues.Keys)
                {
                    CueOption       cue        = signal.Cues[key];
                    SlackAttachment attachment = CreateSlackAttachment(request.Id, key, cue);
                    message.Attachments.Add(attachment);
                }
            }

            return(message);
        }
Ejemplo n.º 6
0
        public static SlackMessage Publish(ChannelRequest request)
        {
            SlackMessage message = CreateSlackMessage(request);

            String webHook = request?.Channel?.Target;

            if (webHook != null)
            {
                SendMessage(webHook, message);
                return(message);
            }
            else
            {
                throw new Exception("No Target Information Was Provided.");
            }
        }
Ejemplo n.º 7
0
        // ******************************************************************
        // *** MessageCard Methods
        // ******************************************************************

        public static MessageCard CreateMessageCardMessage(ChannelRequest request)
        {
            MessageCard message = new MessageCard();
            Signal      signal  = request.Signal;

            message.Title = String.IsNullOrEmpty(signal.Name) ? " " : signal.Name;
            message.Text  = String.IsNullOrEmpty(signal.Description) ? " " : signal.Description;
            if (signal.IncludeId)
            {
                if (String.IsNullOrWhiteSpace(message.Title))
                {
                    message.Title = $"Id: {request.Id}";
                }
                else
                {
                    message.Title += $" (Id: {request.Id})";
                }
            }

            if (signal.Cues != null)
            {
                int totalCues = signal.Cues.Count;
                foreach (string key in signal.Cues.Keys)
                {
                    CueOption          cue     = signal.Cues[key];
                    MessageCardSection section = new MessageCardSection
                    {
                        Title = cue.Name,
                        Text  = cue.Description
                    };
                    message.Sections.Add(section);

                    foreach (SignalVariable cueAction in cue.Actions)
                    {
                        MessageCardAction action = CreateMessageCardAction(request, key, cueAction);
                        if (action != null)
                        {
                            message.PotentialActions.Add(action);
                        }
                    }
                }
            }

            return(message);
        }
Ejemplo n.º 8
0
        public static MessageCard Publish(ChannelRequest request)
        {
            MessageCard message = CreateMessageCardMessage(request);
            string      json    = JsonTools.Serialize(message, true);
            Signal      signal  = request.Signal;

            String webHook = request?.Channel?.Target;

            if (webHook != null)
            {
                SendMessage(webHook, message);
                return(message);
            }
            else
            {
                throw new Exception("No Target Information Was Provided.");
            }
        }
Ejemplo n.º 9
0
        public static MessageCardAction CreateMessageCardAction(ChannelRequest request, string cueId, SignalVariable action)
        {
            string actionUrl = request.Channel?.Config?["actionUrl"]?.ToString();

            MessageCardAction potnetialAction = new MessageCardAction();

            potnetialAction.Name = action.Text;

            Dictionary <string, object> actionBody = new Dictionary <string, object>();

            actionBody.Add("signalId", request.Id);
            actionBody.Add("cueId", cueId);

            if (action.Type == VariableType.choice)
            {
                potnetialAction.Type    = MessageCardActionType.ActionCard;
                potnetialAction.Inputs  = new List <MessageCardInput>();
                potnetialAction.Actions = new List <MessageCardAction>();

                MessageCardInput input = new MessageCardInput();
                input.Type          = MessageCardInputType.MultichoiceInput;
                input.Id            = action.Id;
                input.Title         = action.Text;
                input.Value         = action.DefaultValue;
                input.Style         = MessageCardInputStyle.expanded; // Expanded = Radio Buttons.  Remove for Drop Down"
                input.IsMultiSelect = false;
                input.Choices       = new List <MessageCardInputChoice>();
                foreach (string key in action.Values.Keys)
                {
                    MessageCardInputChoice messageChoice = new MessageCardInputChoice()
                    {
                        Name  = action.Values[key],
                        Value = key
                    };
                    input.Choices.Add(messageChoice);
                }

                potnetialAction.Inputs.Add(input);

                actionBody.Add(action.Id, "{{" + action.Id + ".value}}");
                MessageCardAction submit = new MessageCardAction()
                {
                    Type   = MessageCardActionType.HttpPOST,
                    Name   = "Submit",
                    Target = actionUrl,
                    Body   = JsonTools.Serialize(actionBody)
                };
                potnetialAction.Actions.Add(submit);
            }
            else if (action.Type == VariableType.button)
            {
                actionBody.Add(action.Id, action.DefaultValue);

                potnetialAction.Type   = MessageCardActionType.HttpPOST;
                potnetialAction.Target = actionUrl;
                potnetialAction.Body   = JsonTools.Serialize(actionBody);
            }
            else
            {
                // Unknown or Unsupported Action Type.  Ignore It.
                potnetialAction = null;
            }

            return(potnetialAction);
        }