@akson/cortex-slack

中文文档
2.1.1发布于 2025/10/06MITTypeScriptESM + CJS近 30 天下载 2239

Unified Slack integration for Cortex ecosystem - webhooks, bot API, and notifications

此软件包已被标记为弃用

Deprecated: replaced by @slack/webhook. No longer maintained.

原始使用文档
文档目录18 节
  1. Features
  2. Installation
  3. Quick Start
  4. Basic Usage
  5. Environment Variables
  6. Create from Environment
  7. Usage Examples
  8. Lead Notifications
  9. Error Notifications
  10. Metric Alerts
  11. Task Management
  12. Daily Intelligence Report
  13. Integration with MyArmy Intelligence
  14. Migration Guide
  15. From Direct Webhook
  16. From MyArmy Intelligence
  17. Testing
  18. License

@akson/cortex-slack

Unified Slack integration for the MyArmy ecosystem. Provides centralized notification, alert, and reporting capabilities.

Features

  • 🔔 Webhook Support - Simple notifications via Incoming Webhooks
  • 🤖 Bot API - Full-featured interactive messages and buttons
  • 🚨 Alert System - Severity-based alerts with rich formatting
  • 📊 Reports - Daily/weekly intelligence and market reports
  • 🎯 Lead Tracking - Real-time lead notifications
  • ⚠️ Error Handling - Centralized error notifications
  • 📈 Metrics - Performance and threshold alerts

Installation

npm install @akson/cortex-slack

Quick Start

Basic Usage

import { SlackClient } from '@akson/cortex-slack';

const slack = new SlackClient({
  webhookUrl: 'https://hooks.slack.com/services/YOUR/WEBHOOK/URL',
  botToken: 'xoxb-your-bot-token',
  channels: {
    alerts: '#alerts',
    leads: '#leads',
    reports: '#reports'
  }
});

// Send a simple alert
await slack.sendAlert({
  severity: 'warning',
  message: 'High memory usage detected',
  details: {
    usage: '85%',
    threshold: '80%'
  }
});

Environment Variables

# Webhook (for simple notifications)
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL

# Bot Token (for full API access)
SLACK_BOT_TOKEN=xoxb-your-bot-token
SLACK_APP_ID=your-app-id
SLACK_TEAM_ID=your-team-id
SLACK_TEAM_NAME=your-team-name

# Channel Configuration
SLACK_CHANNEL_ALERTS=#alerts
SLACK_CHANNEL_TASKS=#tasks
SLACK_CHANNEL_REPORTS=#reports
SLACK_CHANNEL_LEADS=#leads
SLACK_CHANNEL_ERRORS=#errors

# Enable/Disable
SLACK_ENABLED=true

Create from Environment

import { createSlackClientFromEnv } from '@akson/cortex-slack';

const slack = createSlackClientFromEnv();

Usage Examples

Lead Notifications

await slack.sendLeadNotification({
  lead_id: 'LEAD-12345',
  phone: '+41791234567',
  products: ['Custom Badge', 'Unit Patch'],
  total_value: 249.90,
  source: 'WhatsApp',
  urgency: 'high',
  timestamp: new Date()
});

Error Notifications

await slack.sendErrorNotification({
  error: new Error('Database connection failed'),
  context: 'Lead Processing',
  severity: 'critical',
  stack: error.stack,
  metadata: {
    lead_id: 'LEAD-12345',
    retry_count: 3
  }
});

Metric Alerts

await slack.sendMetricAlert({
  metric: 'Conversion Rate',
  current_value: 1.2,
  threshold: 2.0,
  change_percentage: -40,
  trend: 'down',
  severity: 'warning',
  recommendation: 'Review landing page changes from last deployment'
});

Task Management

await slack.sendTaskReview({
  task: {
    id: 'TASK-001',
    title: 'Update SEO meta tags',
    description: 'Optimize meta descriptions for Swiss military keywords',
    type: 'seo',
    priority: 'high',
    confidence: 0.85,
    estimated_impact: 'High',
    created_at: new Date()
  },
  preview: {
    suggested_changes: [
      'Add "militär badge" to homepage title',
      'Update meta description with "funktionsabzeichen"'
    ]
  },
  action_required: 'Review and approve SEO changes'
});

Daily Intelligence Report

await slack.sendDailyIntelligenceReport({
  date: new Date(),
  sources_checked: 5,
  tasks_generated: 12,
  auto_executed: 8,
  manual_required: 4,
  swiss_market: {
    avg_position: 3.2,
    impressions: 15000,
    clicks: 450,
    ctr: 3.0
  },
  lead_funnel: {
    new_leads: 23,
    conversion_rate: 2.8,
    whatsapp_contacts: 15
  },
  alerts: [
    'Competitor bidding on brand keywords',
    'CTR drop on mobile devices'
  ],
  recommendations: [
    'Increase mobile page speed',
    'Add more Swiss German content'
  ]
});

Integration with MyArmy Intelligence

This package is designed to work seamlessly with the MyArmy Intelligence system:

// In myarmy-intelligence
import { SlackClient } from '@akson/cortex-slack';

const slack = new SlackClient({
  botToken: process.env.SLACK_BOT_TOKEN,
  channels: {
    alerts: '#intelligence-alerts',
    tasks: '#intelligence-tasks',
    reports: '#intelligence-reports'
  }
});

// Use for automated alerts
await slack.sendAlert({
  severity: 'critical',
  message: 'Brand bidding violation detected',
  details: {
    competitor: 'Competitor X',
    keyword: 'myarmy',
    position: 1
  }
});

Migration Guide

From Direct Webhook

// Old way
await fetch(SLACK_WEBHOOK_URL, {
  method: 'POST',
  body: JSON.stringify({ text: 'Hello' })
});

// New way
import { SlackClient } from '@akson/cortex-slack';
const slack = new SlackClient({ webhookUrl: SLACK_WEBHOOK_URL });
await slack.sendWebhookMessage('Hello');

From MyArmy Intelligence

// Old way (custom implementation)
import { SlackNotifier } from './integrations/slack';

// New way
import { SlackClient } from '@akson/cortex-slack';
const slack = new SlackClient(config);

Testing

// Test connection
const isConnected = await slack.testConnection();
console.log('Slack connected:', isConnected);

License

MIT

版本与发布记录

@akson/cortex-slack 共发布 3 个版本,首次发布于 2025/09/13;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.1.1latest2025/10/061.1 年前
2.1.02025/10/061.1 年前
2.0.02025/09/131.1 年前

关于 @akson/cortex-slack 的常见问题

@akson/cortex-slack 是什么?

Unified Slack integration for Cortex ecosystem - webhooks, bot API, and notifications注意:该包已被作者标记为弃用——Deprecated: replaced by @slack/webhook. No longer maintained.

如何安装 @akson/cortex-slack?

在项目目录运行 npm install @akson/cortex-slack,或使用 pnpm add / yarn add / bun add。

@akson/cortex-slack 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@akson/cortex-slack 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@akson/cortex-slack 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@akson/cortex-slack 可以商用吗?

@akson/cortex-slack 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@akson/cortex-slack 的下载量有多少?

根据 npm 官方下载统计,@akson/cortex-slack 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,239 次,日均约 75 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@akson/cortex-slack 还在维护吗?

最新版本 2.1.1 发布于 2025/10/06(1.1 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/09/13。作者已将其标记为弃用,新项目建议寻找替代方案。