public virtual SignalStatus SendToChannel(ChannelDbRecord channel, SignalDbRecord signal) { SignalStatus status = new SignalStatus { Code = StatusCode.Success, ChannelType = channel.Type, Message = "Success" }; try { if (channel.IsActive == false) { status.Code = StatusCode.NotActive; status.Message = "Channel Is Disabled."; } else if (channel.Type == "slack") { SlackMessage message = Slack.Publish(signal.Id, channel, signal.Signal); //status.Message = JsonTools.Serialize(message); } else if (channel.Type == "teams") { MessageCard message = Teams.Publish(signal.Id, channel, signal.Signal); //status.Message = JsonTools.Serialize(message); } else if (channel.Type == "azure-bot-service") { AzureBotService abs = new AzureBotService(); AzureBotServiceMessage message = abs.Publish(signal.Id, channel, signal.Signal); //status.Message = JsonTools.Serialize(message); } else { throw new Exception($"Unknown Channel Type [{channel.Type}]."); } } catch (Exception e) { status.Code = StatusCode.Failure; status.Message = e.Message; } return(status); }
// ****************************************************************** // *** 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); }
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."); } }
public static void SendMessage(string webHook, MessageCard message) { string body = JsonTools.Serialize(message); Utils.PostMessage(webHook, body); }