Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support to Teams workflow webhook #803

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions KeyVault.Acmebot/Internal/LegacyTeamsPayloadBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;

namespace KeyVault.Acmebot.Internal;

internal class LegacyTeamsPayloadBuilder : IWebhookPayloadBuilder
{
public object BuildCompleted(string certificateName, DateTimeOffset? expirationDate, IEnumerable<string> dnsNames, string acmeEndpoint)
{
return new
{
title = "Acmebot",
text = @$"A new certificate has been issued.

**Certificate Name**: {certificateName}

**Expiration Date**: {expirationDate}

**ACME Endpoint**: {acmeEndpoint}

**DNS Names**: {string.Join(", ", dnsNames)}",
themeColor = "2EB886"
};
}

public object BuildFailed(string functionName, string reason)
{
return new
{
title = "Acmebot",
text = @$"**{functionName}**

**Reason**

{reason}",
themeColor = "A30200"
};
}
}
95 changes: 77 additions & 18 deletions KeyVault.Acmebot/Internal/TeamsPayloadBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,90 @@ public object BuildCompleted(string certificateName, DateTimeOffset? expirationD
{
return new
{
title = "Acmebot",
text = @$"A new certificate has been issued.

**Certificate Name**: {certificateName}

**Expiration Date**: {expirationDate}

**ACME Endpoint**: {acmeEndpoint}

**DNS Names**: {string.Join(", ", dnsNames)}",
themeColor = "2EB886"
type = "message",
attachments = new[]
{
new
{
contentType = "application/vnd.microsoft.card.adaptive",
content = new
{
type = "AdaptiveCard",
body = new object[]
{
new
{
type = "TextBlock",
text = "A new certificate has been issued.",
wrap = true
},
new{
type = "FactSet",
facts = new object[]
{
new
{
title = "Certificate Name",
value = certificateName
},
new
{
title = "Expiration Date",
value = expirationDate
},
new
{
title = "ACME Endpoint",
value = acmeEndpoint
},
new
{
title = "DNS Names",
value = string.Join("\n", dnsNames)
}
}
}
}
}
}
}
};
}

public object BuildFailed(string functionName, string reason)
{
return new
{
title = "Acmebot",
text = @$"**{functionName}**

**Reason**

{reason}",
themeColor = "A30200"
type = "message",
attachments = new[]
{
new
{
contentType = "application/vnd.microsoft.card.adaptive",
content = new
{
type = "AdaptiveCard",
body = new object[]
{
new
{
type = "TextBlock",
size = "Medium",
weight = "Bolder",
text = functionName,
style = "heading",
wrap = true
},
new
{
type = "TextBlock",
text = reason,
wrap = true
}
}
}
}
}
};
}
}
7 changes: 6 additions & 1 deletion KeyVault.Acmebot/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,16 @@ public override void Configure(IFunctionsHostBuilder builder)
return new SlackPayloadBuilder();
}

if (options.Webhook.Host.EndsWith(".office.com", StringComparison.OrdinalIgnoreCase))
if (options.Webhook.Host.EndsWith(".logic.azure.com", StringComparison.OrdinalIgnoreCase))
{
return new TeamsPayloadBuilder();
}

if (options.Webhook.Host.EndsWith(".office.com", StringComparison.OrdinalIgnoreCase))
{
return new LegacyTeamsPayloadBuilder();
}

return new GenericPayloadBuilder(options);
});

Expand Down
Loading