Ejemplo n.º 1
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.º 2
0
        public static void SendMessage(string webHook, SlackMessage message)
        {
            string body = JsonTools.Serialize(message);

            Utils.PostMessage(webHook, body);
        }
Ejemplo n.º 3
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);
        }