public static SlackAction CreateSlackAction(SignalVariable action) { SlackAction slackAction = new SlackAction(); slackAction.Name = action.Id; slackAction.Value = action.DefaultValue; switch (action.Type) { case VariableType.choice: slackAction.Type = SlackActionType.select; slackAction.Options = new List <SlackSelectOption>(); foreach (string key in action.Values.Keys) { SlackSelectOption option = new SlackSelectOption(); option.Text = action.Values[key]; option.Value = key; slackAction.Options.Add(option); } break; case VariableType.button: slackAction.Type = SlackActionType.button; slackAction.Text = action.Text; break; } return(slackAction); }
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); }