private static object BuildSlackPayload(HookData hookData) { var updates = string.Join('\n', hookData.updates.Select(update => { if (!update.oldValue.HasValue && !update.newValue.HasValue) { return(""); } if (!update.newValue.HasValue) { return($"key path: `{update.oldValue.Value.keyPath}`\ndeleted\n```{update.oldValue.Value.implementation}```"); } if (!update.oldValue.HasValue) { return($"key path: `{update.newValue.Value.keyPath}`\ncreated\n```{update.newValue.Value.implementation}```"); } return($"key path: `{update.newValue.Value.keyPath}`\nold:\n```{update.oldValue.Value.implementation}```\nnew:\n```{update.newValue.Value.implementation}```"); })); var text = $"Tweek key changed!\n{updates}\nChanged by: {hookData.author.name} <{hookData.author.email}>"; return(new { text }); }
private async Task TriggerHook(Hook hook, HookData hookData) { switch (hook.Type) { case "notification_webhook": var transformFunc = _transformDataByHookFormat.ContainsKey(hook.Format) ? _transformDataByHookFormat[hook.Format] : data => data; await TriggerWebhook(hook.Url, transformFunc(hookData)); break; default: throw new Exception($"Failed to trigger hook, invalid type: {hook.Type}"); } }