AI
Copy these instructions into a coding agent to add Slack Bridge to another app quickly.
Agent prompt
You are adding Slack Bridge event notifications to this application.
Slack Bridge is already hosted separately. Do not build Slack delivery in this app.
Configuration to use:
- SlackBridge:BaseUrl = https://your-slack-bridge.example.com
- SlackBridge:ApiKey = sb_your_bot_key
HTTP contract:
- Method: POST
- Path: /api/events
- Header: x-api-key: {SlackBridge:ApiKey}
- Body:
{
"key": "stable_event_key",
"data": {
"field": "value"
}
}
Implementation requirements:
- Create a small typed client/service named SlackBridgeClient.
- Register it with dependency injection and HttpClient.
- Keep the API key in secret configuration.
- Use stable event keys such as user_signup, payment_failed, build_failed, or job_completed.
- Send plain JSON data. Slack Bridge handles Slack formatting through templates.
- Do not store or log the full API key.
- Treat non-success responses as failures and surface useful diagnostics.
- Add one event call at the feature boundary I describe below.
- Add a focused test or smoke check if this codebase already has tests for HTTP clients.
Task:
Implement the Slack Bridge event described here: [describe the event, where it happens, and the payload fields].
Slash command downstream prompt
You are integrating this application with Slack Bridge inbound slash commands.
Slack Bridge is already hosted separately. Do not verify Slack signatures in this app; Slack Bridge does that.
Do not build Slack app setup, Socket Mode, modals, App Home, or Slack-specific persistence unless explicitly asked.
Configuration to use:
- SlackBridge:SlashCommandSecret = shared_secret_from_slackbridge_route
HTTP contract from Slack Bridge:
- Method: POST
- Content-Type: application/json
- Header: x-slackbridge-secret: {SlackBridge:SlashCommandSecret}
- Body:
{
"type": "slash_command",
"teamId": "T123",
"teamDomain": "example",
"channelId": "C123",
"channelName": "general",
"userId": "U123",
"userName": "deprecated_from_slack_if_present_but_not_required",
"command": "/shoppingtajm",
"text": "list",
"triggerId": "...",
"responseUrl": "...",
"apiAppId": "...",
"raw": {}
}
Response contract:
- Return 200 with Slack-compatible JSON to reply immediately.
- Return 204 for an empty acknowledgement.
- Return 4xx/5xx only when Slack Bridge should show its safe fallback response.
Implementation requirements:
- Authenticate the shared secret header.
- Keep domain parsing and business logic inside this app.
- Return Slack JSON such as { "response_type": "ephemeral", "text": "..." }.
- Do not log the shared secret or Slack response_url.
- Add focused tests for command parsing and response behavior if this codebase has tests.
Task:
Implement the downstream callback for this command: [describe command behavior].
Reference client
public sealed class SlackBridgeClient(HttpClient httpClient, IConfiguration configuration)
{
public async Task SendAsync(string key, object data, CancellationToken cancellationToken = default)
{
using var request = new HttpRequestMessage(HttpMethod.Post, "/api/events");
request.Headers.Add("x-api-key", configuration["SlackBridge:ApiKey"]);
request.Content = JsonContent.Create(new { key, data });
using var response = await httpClient.SendAsync(request, cancellationToken);
response.EnsureSuccessStatusCode();
}
}
builder.Services.AddHttpClient<SlackBridgeClient>(client =>
{
client.BaseAddress = new Uri(builder.Configuration["SlackBridge:BaseUrl"]!);
});
Slack setup links
What Slack Bridge does
Slack Bridge is a single-tenant ASP.NET Core 9 application that receives event payloads from internal apps, renders Scriban templates, sends messages through Slack bot webhooks, and forwards verified Slack slash commands to downstream application callbacks.
The app uses Razor Pages, Web API controllers, ASP.NET Core Identity, EF Core with SQL Server, hashed API keys, local plan enforcement, event logs, inbound command logs, and a hosted retry worker for failed Slack deliveries.
Slack Bridge repo maintenance prompt
You are working on Slack Bridge.
Goal: fix or add an integration without changing unrelated behavior.
Architecture:
- .NET 9 ASP.NET Core monolith.
- Razor Pages admin UI under /Pages/Admin, with Slack bots as the main workspace.
- Web API endpoints: POST /api/events and POST /api/slack/commands.
- EF Core SQL Server DbContext: SlackBridgeDbContext.
- Identity user model: ApplicationUser.
- Customer-scoped data uses CustomerInstanceId.
- User-facing admin pages use the signed-in user's tenant.
- API event ingestion uses the tenant from the API key.
Core event flow:
1. Validate x-api-key using IApiKeyValidator.
2. Find active EventDefinition for the API key's Slack bot and event key.
3. Enforce usage limits with IUsageService.
4. Render the Scriban template with ITemplateService.
5. Send the rendered text through ISlackService using the Slack bot webhook URL, unless the event definition has its disabled-by-default custom webhook override enabled.
6. Write EventLog for success or failure.
7. Mark failed Slack sends for retry with FailedSlackRetryWorker.
Inbound slash command flow:
1. Receive application/x-www-form-urlencoded Slack slash command posts at /api/slack/commands.
2. Verify X-Slack-Signature and X-Slack-Request-Timestamp with ISlackRequestVerifier.
3. Match an active SlackCommandRoute by command and optional Slack team ID.
4. Forward normalized SlackCommandEnvelope JSON through IDownstreamSlackCommandClient.
5. Relay downstream Slack JSON, return empty 200 for 204, or return a safe ephemeral fallback on failure.
6. Write SlackCommandLog rows for validation, routing, downstream status, and fallback outcomes.
Important files:
- Controllers/EventsController.cs
- Controllers/SlackCommandsController.cs
- Data/SlackBridgeDbContext.cs
- Models/Project.cs
- Models/ApiKey.cs
- Models/EventDefinition.cs
- Models/EventLog.cs
- Models/SlackCommandRoute.cs
- Models/SlackCommandLog.cs
- Services/EventIngestionService.cs
- Services/SlackCommandGatewayService.cs
- Services/SlackRequestVerifier.cs
- Services/SlackCommandForwarder.cs
- Services/SlackService.cs
- Services/TemplateService.cs
- Services/UsageService.cs
- Services/FailedSlackRetryWorker.cs
- Pages/Admin/EventDefinitions/
- Pages/Admin/SlackCommandRoutes/
- Pages/Admin/Projects/Details.cshtml
Rules:
- Keep changes small and production-ready.
- Use dependency injection.
- Do not store raw API keys.
- Do not store Slack signing secrets or downstream shared secrets in plain text.
- Do not bypass Identity for admin pages.
- Do not hardcode customer-specific logic outside ICustomerInstanceContext.
- Do not implement app-specific slash command logic in SlackBridge.
- Add or update EF migrations when the database model changes.
- Run dotnet build before finishing.
Task:
Fix the integration issue described below.
Integration checklist
- Confirm the caller sends
x-api-key. - Confirm the API key is active and belongs to the expected Slack bot.
- Confirm the event key exactly matches an active event definition.
- Render the Scriban template with representative JSON.
- Check the Slack bot webhook URL, any enabled event-level override, and response status.
- Inspect
EventLogsfor result messages and retry state. - Inspect
SlackCommandLogsfor slash command validation and downstream outcomes. - Check monthly usage limits if requests return
429.
Useful request shape
POST /api/events
x-api-key: sb_...
{
"key": "user_signup",
"data": {
"email": "user@example.com",
"plan": "pro"
}
}