Пример #1
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);
        }
Пример #2
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);
        }