MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / sendOrganizationAlert

Function sendOrganizationAlert

packages/billing/src/org-monitoring.ts:129–195  ·  view source on GitHub ↗
(
  params: OrganizationCreditAlert & {
    logger: Logger
  },
)

Source from the content-addressed store, hash-verified

127 * Sends alerts for organization credit issues
128 */
129export async function sendOrganizationAlert(
130 params: OrganizationCreditAlert & {
131 logger: Logger
132 },
133): Promise<void> {
134 const {
135 organizationId,
136 alertType,
137 currentBalance,
138 threshold,
139 usageAmount,
140 error,
141 metadata,
142 logger,
143 } = params
144
145 try {
146 // Log the alert
147 logger.warn(
148 {
149 organizationId,
150 alertType,
151 currentBalance,
152 threshold,
153 usageAmount,
154 error: error,
155 metadata: metadata,
156 },
157 `Organization alert: ${alertType}`,
158 )
159
160 // Track analytics event
161 trackEvent({
162 event: AnalyticsEvent.CREDIT_GRANT,
163 userId: organizationId,
164 properties: {
165 alertType,
166 currentBalance,
167 threshold,
168 },
169 logger,
170 })
171
172 // TODO: Implement actual alerting mechanisms:
173 // - Email notifications to organization owners
174 // - Slack/Discord webhooks
175 // - Dashboard notifications
176 // - SMS alerts for critical issues
177
178 switch (alertType) {
179 case 'low_balance':
180 await handleLowBalanceAlert(params)
181 break
182 case 'high_usage':
183 await handleHighUsageAlert(params)
184 break
185 case 'failed_consumption':
186 await handleFailedConsumptionAlert(params)

Callers 1

Calls 5

trackEventFunction · 0.90
handleLowBalanceAlertFunction · 0.85
handleHighUsageAlertFunction · 0.85
handleBillingSetupAlertFunction · 0.85

Tested by

no test coverage detected