コード例 #1
0
        public static SlackAttachment CreateSlackAttachment(string signalId, string cueId, CueOption cue)
        {
            SlackAttachment attachment = new SlackAttachment();

            string cueTitle = $"{cue.Name}\n{cue.Description}";

            if (String.IsNullOrEmpty(cue.Name))
            {
                cueTitle = cue.Description;
            }
            else if (String.IsNullOrEmpty(cue.Description))
            {
                cueTitle = cue.Name;
            }
            attachment.Text       = cueTitle;
            attachment.CallbackId = $"{signalId}|{cueId}";

            foreach (SignalVariable action in cue.Actions)
            {
                SlackAction slackAction = CreateSlackAction(action);
                attachment.Actions.Add(slackAction);
            }


            return(attachment);
        }
コード例 #2
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);
        }