Exemple #1
0
        public static Cue CreateCue(SlackReply reply)
        {
            if (reply.BodyJson != null)
            {
                // Reply Came Directly From Slack.  Decode the payload
                string body = reply.BodyJson;
                if (body.StartsWith("payload=", StringComparison.OrdinalIgnoreCase))
                {
                    body          = body.Replace("payload=", "", StringComparison.OrdinalIgnoreCase);
                    body          = body.Replace('+', ' ');
                    body          = HttpUtility.UrlDecode(body);
                    reply.Payload = JsonTools.Deserialize <SlackPayload>(body);
                }
            }

            SlackPayload payload = reply?.Payload;

            if (payload == null)
            {
                throw new Exception("Slack Reply Payload Not Found.");
            }

            string callbackId = payload.CallbackId;
            string signalId   = callbackId.Split('|')[0];
            string cueId      = HttpUtility.HtmlDecode(callbackId.Split('|')[1]);

            Cue cue = new Cue
            {
                Id      = signalId,
                CueId   = cueId,
                Payload = payload
            };

            foreach (SlackReplyAction actionReply in payload.Actions)
            {
                MultiValueVariable actionVariable = new MultiValueVariable();
                actionVariable.Name = actionReply.Name;

                if (actionReply.Type == "select")
                {
                    foreach (Dictionary <string, string> option in actionReply.SelectedOptions)
                    {
                        actionVariable.Values.Add(option["value"]);
                    }
                }
                else if (actionReply.Type == "button")
                {
                    actionVariable.Values.Add(actionReply.Value);
                }

                cue.Variables.Add(actionVariable);
            }

            return(cue);
        }
        public string GetConversationId()
        {
            Dictionary <string, string> headers = new Dictionary <string, string>
            {
                { "Authorization", $"Bearer {BearerToken}" }
            };

            WebResponse response = Utils.PostMessage(BaseUrl, null, headers);
            String      payload  = Utils.GetPayload(response);

            ConversationIdReply reply = JsonTools.Deserialize <ConversationIdReply>(payload);

            return(reply.ConversationId);
        }