opc-agent 4.1.1 → 4.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analytics/index.d.ts.map +1 -0
- package/dist/analytics/index.js.map +1 -0
- package/dist/channels/dingtalk.d.ts.map +1 -0
- package/dist/channels/dingtalk.js.map +1 -0
- package/dist/channels/discord.d.ts.map +1 -0
- package/dist/channels/discord.js.map +1 -0
- package/dist/channels/email.d.ts.map +1 -0
- package/dist/channels/email.js.map +1 -0
- package/dist/channels/feishu.d.ts.map +1 -0
- package/dist/channels/feishu.js.map +1 -0
- package/dist/channels/googlechat.d.ts.map +1 -0
- package/dist/channels/googlechat.js.map +1 -0
- package/dist/channels/imessage.d.ts.map +1 -0
- package/dist/channels/imessage.js.map +1 -0
- package/dist/channels/index.d.ts.map +1 -0
- package/dist/channels/index.js.map +1 -0
- package/dist/channels/irc.d.ts.map +1 -0
- package/dist/channels/irc.js.map +1 -0
- package/dist/channels/line.d.ts.map +1 -0
- package/dist/channels/line.js.map +1 -0
- package/dist/channels/matrix.d.ts.map +1 -0
- package/dist/channels/matrix.js.map +1 -0
- package/dist/channels/mattermost.d.ts.map +1 -0
- package/dist/channels/mattermost.js.map +1 -0
- package/dist/channels/msteams.d.ts.map +1 -0
- package/dist/channels/msteams.js.map +1 -0
- package/dist/channels/nostr.d.ts.map +1 -0
- package/dist/channels/nostr.js.map +1 -0
- package/dist/channels/qq.d.ts.map +1 -0
- package/dist/channels/qq.js.map +1 -0
- package/dist/channels/signal.d.ts.map +1 -0
- package/dist/channels/signal.js.map +1 -0
- package/dist/channels/slack.d.ts.map +1 -0
- package/dist/channels/slack.js.map +1 -0
- package/dist/channels/sms.d.ts.map +1 -0
- package/dist/channels/sms.js.map +1 -0
- package/dist/channels/telegram.d.ts.map +1 -0
- package/dist/channels/telegram.js.map +1 -0
- package/dist/channels/twitch.d.ts.map +1 -0
- package/dist/channels/twitch.js.map +1 -0
- package/dist/channels/voice-call.d.ts.map +1 -0
- package/dist/channels/voice-call.js.map +1 -0
- package/dist/channels/voice.d.ts.map +1 -0
- package/dist/channels/voice.js.map +1 -0
- package/dist/channels/web.d.ts.map +1 -0
- package/dist/channels/web.js +8 -2
- package/dist/channels/web.js.map +1 -0
- package/dist/channels/webhook.d.ts.map +1 -0
- package/dist/channels/webhook.js.map +1 -0
- package/dist/channels/websocket.d.ts.map +1 -0
- package/dist/channels/websocket.js.map +1 -0
- package/dist/channels/wechat.d.ts.map +1 -0
- package/dist/channels/wechat.js.map +1 -0
- package/dist/channels/whatsapp.d.ts.map +1 -0
- package/dist/channels/whatsapp.js.map +1 -0
- package/dist/cli/chat.d.ts.map +1 -0
- package/dist/cli/chat.js.map +1 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +261 -85
- package/dist/cli.js.map +1 -0
- package/dist/core/a2a.d.ts.map +1 -0
- package/dist/core/a2a.js.map +1 -0
- package/dist/core/agent.d.ts.map +1 -0
- package/dist/core/agent.js.map +1 -0
- package/dist/core/analytics-engine.d.ts.map +1 -0
- package/dist/core/analytics-engine.js.map +1 -0
- package/dist/core/api-server.d.ts.map +1 -0
- package/dist/core/api-server.js.map +1 -0
- package/dist/core/audio.d.ts.map +1 -0
- package/dist/core/audio.js.map +1 -0
- package/dist/core/auth.d.ts.map +1 -0
- package/dist/core/auth.js.map +1 -0
- package/dist/core/cache.d.ts.map +1 -0
- package/dist/core/cache.js.map +1 -0
- package/dist/core/collaboration.d.ts.map +1 -0
- package/dist/core/collaboration.js.map +1 -0
- package/dist/core/compose.d.ts.map +1 -0
- package/dist/core/compose.js.map +1 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/context-discovery.d.ts.map +1 -0
- package/dist/core/context-discovery.js.map +1 -0
- package/dist/core/context-refs.d.ts.map +1 -0
- package/dist/core/context-refs.js.map +1 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/gateway.d.ts.map +1 -0
- package/dist/core/gateway.js.map +1 -0
- package/dist/core/heartbeat.d.ts.map +1 -0
- package/dist/core/heartbeat.js.map +1 -0
- package/dist/core/hitl.d.ts.map +1 -0
- package/dist/core/hitl.js.map +1 -0
- package/dist/core/hooks.d.ts.map +1 -0
- package/dist/core/hooks.js.map +1 -0
- package/dist/core/ide-bridge.d.ts.map +1 -0
- package/dist/core/ide-bridge.js.map +1 -0
- package/dist/core/knowledge.d.ts.map +1 -0
- package/dist/core/knowledge.js.map +1 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/node-network.d.ts.map +1 -0
- package/dist/core/node-network.js.map +1 -0
- package/dist/core/orchestrator.d.ts.map +1 -0
- package/dist/core/orchestrator.js.map +1 -0
- package/dist/core/performance.d.ts.map +1 -0
- package/dist/core/performance.js.map +1 -0
- package/dist/core/profiles.d.ts.map +1 -0
- package/dist/core/profiles.js.map +1 -0
- package/dist/core/rate-limiter.d.ts.map +1 -0
- package/dist/core/rate-limiter.js.map +1 -0
- package/dist/core/room.d.ts.map +1 -0
- package/dist/core/room.js.map +1 -0
- package/dist/core/runtime.d.ts.map +1 -0
- package/dist/core/runtime.js +37 -15
- package/dist/core/runtime.js.map +1 -0
- package/dist/core/sandbox.d.ts.map +1 -0
- package/dist/core/sandbox.js.map +1 -0
- package/dist/core/scheduler.d.ts.map +1 -0
- package/dist/core/scheduler.js.map +1 -0
- package/dist/core/security.d.ts.map +1 -0
- package/dist/core/security.js.map +1 -0
- package/dist/core/session-manager.d.ts.map +1 -0
- package/dist/core/session-manager.js.map +1 -0
- package/dist/core/streaming.d.ts.map +1 -0
- package/dist/core/streaming.js.map +1 -0
- package/dist/core/subagent.d.ts.map +1 -0
- package/dist/core/subagent.js.map +1 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/versioning.d.ts.map +1 -0
- package/dist/core/versioning.js.map +1 -0
- package/dist/core/vision.d.ts.map +1 -0
- package/dist/core/vision.js.map +1 -0
- package/dist/core/watch.d.ts.map +1 -0
- package/dist/core/watch.js.map +1 -0
- package/dist/core/workflow-graph.d.ts.map +1 -0
- package/dist/core/workflow-graph.js.map +1 -0
- package/dist/core/workflow.d.ts.map +1 -0
- package/dist/core/workflow.js.map +1 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js.map +1 -0
- package/dist/deploy/hermes.d.ts.map +1 -0
- package/dist/deploy/hermes.js.map +1 -0
- package/dist/deploy/index.d.ts.map +1 -0
- package/dist/deploy/index.js.map +1 -0
- package/dist/deploy/openclaw.d.ts.map +1 -0
- package/dist/deploy/openclaw.js.map +1 -0
- package/dist/doctor.d.ts +1 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +105 -10
- package/dist/doctor.js.map +1 -0
- package/dist/eval/index.d.ts.map +1 -0
- package/dist/eval/index.js.map +1 -0
- package/dist/hub/brain-seed.d.ts.map +1 -0
- package/dist/hub/brain-seed.js.map +1 -0
- package/dist/hub/client.d.ts.map +1 -0
- package/dist/hub/client.js.map +1 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/servers/calculator-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/calculator-mcp.js.map +1 -0
- package/dist/mcp/servers/crypto-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/crypto-mcp.js.map +1 -0
- package/dist/mcp/servers/database-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/database-mcp.js.map +1 -0
- package/dist/mcp/servers/datetime-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/datetime-mcp.js.map +1 -0
- package/dist/mcp/servers/filesystem.d.ts.map +1 -0
- package/dist/mcp/servers/filesystem.js.map +1 -0
- package/dist/mcp/servers/github-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/github-mcp.js.map +1 -0
- package/dist/mcp/servers/index.d.ts.map +1 -0
- package/dist/mcp/servers/index.js.map +1 -0
- package/dist/mcp/servers/json-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/json-mcp.js.map +1 -0
- package/dist/mcp/servers/memory-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/memory-mcp.js.map +1 -0
- package/dist/mcp/servers/regex-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/regex-mcp.js.map +1 -0
- package/dist/mcp/servers/web-mcp.d.ts.map +1 -0
- package/dist/mcp/servers/web-mcp.js.map +1 -0
- package/dist/memory/context-compressor.d.ts.map +1 -0
- package/dist/memory/context-compressor.js.map +1 -0
- package/dist/memory/deepbrain.d.ts +1 -1
- package/dist/memory/deepbrain.d.ts.map +1 -0
- package/dist/memory/deepbrain.js +95 -4
- package/dist/memory/deepbrain.js.map +1 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/seed-loader.d.ts.map +1 -0
- package/dist/memory/seed-loader.js.map +1 -0
- package/dist/memory/user-profiler.d.ts.map +1 -0
- package/dist/memory/user-profiler.js.map +1 -0
- package/dist/plugins/content-filter.d.ts.map +1 -0
- package/dist/plugins/content-filter.js.map +1 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/logger.d.ts.map +1 -0
- package/dist/plugins/logger.js.map +1 -0
- package/dist/plugins/rate-limiter.d.ts.map +1 -0
- package/dist/plugins/rate-limiter.js.map +1 -0
- package/dist/protocols/a2a/client.d.ts.map +1 -0
- package/dist/protocols/a2a/client.js.map +1 -0
- package/dist/protocols/a2a/index.d.ts.map +1 -0
- package/dist/protocols/a2a/index.js.map +1 -0
- package/dist/protocols/a2a/server.d.ts.map +1 -0
- package/dist/protocols/a2a/server.js.map +1 -0
- package/dist/protocols/a2a/types.d.ts.map +1 -0
- package/dist/protocols/a2a/types.js.map +1 -0
- package/dist/protocols/a2a/utils.d.ts.map +1 -0
- package/dist/protocols/a2a/utils.js.map +1 -0
- package/dist/protocols/agui/client.d.ts.map +1 -0
- package/dist/protocols/agui/client.js.map +1 -0
- package/dist/protocols/agui/index.d.ts.map +1 -0
- package/dist/protocols/agui/index.js.map +1 -0
- package/dist/protocols/agui/server.d.ts.map +1 -0
- package/dist/protocols/agui/server.js.map +1 -0
- package/dist/protocols/agui/types.d.ts.map +1 -0
- package/dist/protocols/agui/types.js.map +1 -0
- package/dist/protocols/index.d.ts.map +1 -0
- package/dist/protocols/index.js.map +1 -0
- package/dist/protocols/mcp/agent-tools.d.ts.map +1 -0
- package/dist/protocols/mcp/agent-tools.js.map +1 -0
- package/dist/protocols/mcp/index.d.ts.map +1 -0
- package/dist/protocols/mcp/index.js.map +1 -0
- package/dist/protocols/mcp/server.d.ts.map +1 -0
- package/dist/protocols/mcp/server.js.map +1 -0
- package/dist/protocols/mcp/types.d.ts.map +1 -0
- package/dist/protocols/mcp/types.js.map +1 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/publish/index.d.ts.map +1 -0
- package/dist/publish/index.js.map +1 -0
- package/dist/scheduler/cron-engine.d.ts.map +1 -0
- package/dist/scheduler/cron-engine.js +3 -36
- package/dist/scheduler/cron-engine.js.map +1 -0
- package/dist/scheduler/index.d.ts.map +1 -0
- package/dist/scheduler/index.js.map +1 -0
- package/dist/schema/oad.d.ts.map +1 -0
- package/dist/schema/oad.js.map +1 -0
- package/dist/security/approval.d.ts.map +1 -0
- package/dist/security/approval.js.map +1 -0
- package/dist/security/approvals.d.ts.map +1 -0
- package/dist/security/approvals.js.map +1 -0
- package/dist/security/elevated.d.ts.map +1 -0
- package/dist/security/elevated.js.map +1 -0
- package/dist/security/guardrails.d.ts.map +1 -0
- package/dist/security/guardrails.js.map +1 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/keys.d.ts.map +1 -0
- package/dist/security/keys.js.map +1 -0
- package/dist/security/secrets.d.ts.map +1 -0
- package/dist/security/secrets.js.map +1 -0
- package/dist/skills/auto-learn.d.ts.map +1 -0
- package/dist/skills/auto-learn.js.map +1 -0
- package/dist/skills/base.d.ts.map +1 -0
- package/dist/skills/base.js.map +1 -0
- package/dist/skills/builtin/index.d.ts.map +1 -0
- package/dist/skills/builtin/index.js.map +1 -0
- package/dist/skills/document.d.ts.map +1 -0
- package/dist/skills/document.js.map +1 -0
- package/dist/skills/http.d.ts.map +1 -0
- package/dist/skills/http.js.map +1 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/marketplace.d.ts.map +1 -0
- package/dist/skills/marketplace.js.map +1 -0
- package/dist/skills/scheduler.d.ts.map +1 -0
- package/dist/skills/scheduler.js.map +1 -0
- package/dist/skills/types.d.ts.map +1 -0
- package/dist/skills/types.js.map +1 -0
- package/dist/skills/webhook-trigger.d.ts.map +1 -0
- package/dist/skills/webhook-trigger.js.map +1 -0
- package/dist/studio/server.d.ts.map +1 -0
- package/dist/studio/server.js.map +1 -0
- package/dist/studio/templates-data.d.ts.map +1 -0
- package/dist/studio/templates-data.js.map +1 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/templates/code-reviewer.d.ts.map +1 -0
- package/dist/templates/code-reviewer.js.map +1 -0
- package/dist/templates/content-writer.d.ts.map +1 -0
- package/dist/templates/content-writer.js.map +1 -0
- package/dist/templates/customer-service.d.ts.map +1 -0
- package/dist/templates/customer-service.js.map +1 -0
- package/dist/templates/data-analyst.d.ts.map +1 -0
- package/dist/templates/data-analyst.js.map +1 -0
- package/dist/templates/executive-assistant.d.ts.map +1 -0
- package/dist/templates/executive-assistant.js.map +1 -0
- package/dist/templates/financial-advisor.d.ts.map +1 -0
- package/dist/templates/financial-advisor.js.map +1 -0
- package/dist/templates/hr-recruiter.d.ts.map +1 -0
- package/dist/templates/hr-recruiter.js.map +1 -0
- package/dist/templates/knowledge-base.d.ts.map +1 -0
- package/dist/templates/knowledge-base.js.map +1 -0
- package/dist/templates/legal-assistant.d.ts.map +1 -0
- package/dist/templates/legal-assistant.js.map +1 -0
- package/dist/templates/project-manager.d.ts.map +1 -0
- package/dist/templates/project-manager.js.map +1 -0
- package/dist/templates/sales-assistant.d.ts.map +1 -0
- package/dist/templates/sales-assistant.js.map +1 -0
- package/dist/templates/teacher.d.ts.map +1 -0
- package/dist/templates/teacher.js.map +1 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/tools/builtin/browser.d.ts.map +1 -0
- package/dist/tools/builtin/browser.js.map +1 -0
- package/dist/tools/builtin/datetime.d.ts.map +1 -0
- package/dist/tools/builtin/datetime.js.map +1 -0
- package/dist/tools/builtin/file.d.ts.map +1 -0
- package/dist/tools/builtin/file.js.map +1 -0
- package/dist/tools/builtin/home-assistant.d.ts.map +1 -0
- package/dist/tools/builtin/home-assistant.js.map +1 -0
- package/dist/tools/builtin/index.d.ts.map +1 -0
- package/dist/tools/builtin/index.js.map +1 -0
- package/dist/tools/builtin/rl-tools.d.ts.map +1 -0
- package/dist/tools/builtin/rl-tools.js.map +1 -0
- package/dist/tools/builtin/shell.d.ts.map +1 -0
- package/dist/tools/builtin/shell.js.map +1 -0
- package/dist/tools/builtin/vision.d.ts.map +1 -0
- package/dist/tools/builtin/vision.js.map +1 -0
- package/dist/tools/builtin/web-search.d.ts.map +1 -0
- package/dist/tools/builtin/web-search.js.map +1 -0
- package/dist/tools/builtin/web.d.ts.map +1 -0
- package/dist/tools/builtin/web.js.map +1 -0
- package/dist/tools/calculator.d.ts.map +1 -0
- package/dist/tools/calculator.js.map +1 -0
- package/dist/tools/datetime.d.ts.map +1 -0
- package/dist/tools/datetime.js.map +1 -0
- package/dist/tools/document-processor.d.ts.map +1 -0
- package/dist/tools/document-processor.js.map +1 -0
- package/dist/tools/gateway.d.ts.map +1 -0
- package/dist/tools/gateway.js.map +1 -0
- package/dist/tools/image-generator.d.ts.map +1 -0
- package/dist/tools/image-generator.js.map +1 -0
- package/dist/tools/integrations/calendar.d.ts.map +1 -0
- package/dist/tools/integrations/calendar.js.map +1 -0
- package/dist/tools/integrations/code-exec.d.ts.map +1 -0
- package/dist/tools/integrations/code-exec.js.map +1 -0
- package/dist/tools/integrations/csv-analyzer.d.ts.map +1 -0
- package/dist/tools/integrations/csv-analyzer.js.map +1 -0
- package/dist/tools/integrations/database.d.ts.map +1 -0
- package/dist/tools/integrations/database.js.map +1 -0
- package/dist/tools/integrations/email-send.d.ts.map +1 -0
- package/dist/tools/integrations/email-send.js.map +1 -0
- package/dist/tools/integrations/git-tool.d.ts.map +1 -0
- package/dist/tools/integrations/git-tool.js.map +1 -0
- package/dist/tools/integrations/github-tool.d.ts.map +1 -0
- package/dist/tools/integrations/github-tool.js.map +1 -0
- package/dist/tools/integrations/image-gen.d.ts.map +1 -0
- package/dist/tools/integrations/image-gen.js.map +1 -0
- package/dist/tools/integrations/index.d.ts.map +1 -0
- package/dist/tools/integrations/index.js.map +1 -0
- package/dist/tools/integrations/jira.d.ts.map +1 -0
- package/dist/tools/integrations/jira.js.map +1 -0
- package/dist/tools/integrations/notion.d.ts.map +1 -0
- package/dist/tools/integrations/notion.js.map +1 -0
- package/dist/tools/integrations/npm-tool.d.ts.map +1 -0
- package/dist/tools/integrations/npm-tool.js.map +1 -0
- package/dist/tools/integrations/pdf-reader.d.ts.map +1 -0
- package/dist/tools/integrations/pdf-reader.js.map +1 -0
- package/dist/tools/integrations/slack.d.ts.map +1 -0
- package/dist/tools/integrations/slack.js.map +1 -0
- package/dist/tools/integrations/summarizer.d.ts.map +1 -0
- package/dist/tools/integrations/summarizer.js.map +1 -0
- package/dist/tools/integrations/translator.d.ts.map +1 -0
- package/dist/tools/integrations/translator.js.map +1 -0
- package/dist/tools/integrations/trello.d.ts.map +1 -0
- package/dist/tools/integrations/trello.js.map +1 -0
- package/dist/tools/integrations/vector-search.d.ts.map +1 -0
- package/dist/tools/integrations/vector-search.js.map +1 -0
- package/dist/tools/integrations/web-scraper.d.ts.map +1 -0
- package/dist/tools/integrations/web-scraper.js.map +1 -0
- package/dist/tools/integrations/web-search.d.ts.map +1 -0
- package/dist/tools/integrations/web-search.js.map +1 -0
- package/dist/tools/integrations/webhook.d.ts.map +1 -0
- package/dist/tools/integrations/webhook.js.map +1 -0
- package/dist/tools/json-transform.d.ts.map +1 -0
- package/dist/tools/json-transform.js.map +1 -0
- package/dist/tools/mcp-client.d.ts.map +1 -0
- package/dist/tools/mcp-client.js.map +1 -0
- package/dist/tools/mcp.d.ts.map +1 -0
- package/dist/tools/mcp.js.map +1 -0
- package/dist/tools/text-analysis.d.ts.map +1 -0
- package/dist/tools/text-analysis.js.map +1 -0
- package/dist/tools/web-scraper.d.ts.map +1 -0
- package/dist/tools/web-scraper.js.map +1 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/traces/index.d.ts.map +1 -0
- package/dist/traces/index.js.map +1 -0
- package/dist/ui/components.d.ts.map +1 -0
- package/dist/ui/components.js.map +1 -0
- package/package.json +1 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -20
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -14
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -13
- package/.github/workflows/ci.yml +0 -24
- package/docs/.vitepress/config.ts +0 -103
- package/docs/api/cli.md +0 -48
- package/docs/api/oad-schema.md +0 -64
- package/docs/api/sdk.md +0 -80
- package/docs/guide/concepts.md +0 -51
- package/docs/guide/configuration.md +0 -79
- package/docs/guide/deployment.md +0 -42
- package/docs/guide/getting-started.md +0 -44
- package/docs/guide/templates.md +0 -28
- package/docs/guide/testing.md +0 -84
- package/docs/index.md +0 -27
- package/docs/zh/api/cli.md +0 -54
- package/docs/zh/api/oad-schema.md +0 -87
- package/docs/zh/api/sdk.md +0 -102
- package/docs/zh/guide/concepts.md +0 -104
- package/docs/zh/guide/configuration.md +0 -135
- package/docs/zh/guide/deployment.md +0 -81
- package/docs/zh/guide/getting-started.md +0 -82
- package/docs/zh/guide/templates.md +0 -84
- package/docs/zh/guide/testing.md +0 -88
- package/docs/zh/index.md +0 -27
- package/fix-sidebar.mjs +0 -188
- package/serve-studio.js +0 -13
- package/serve-test.js +0 -25
- package/src/analytics/index.ts +0 -66
- package/src/channels/dingtalk.ts +0 -46
- package/src/channels/discord.ts +0 -192
- package/src/channels/email.ts +0 -351
- package/src/channels/feishu.ts +0 -349
- package/src/channels/googlechat.ts +0 -42
- package/src/channels/imessage.ts +0 -32
- package/src/channels/index.ts +0 -15
- package/src/channels/irc.ts +0 -82
- package/src/channels/line.ts +0 -33
- package/src/channels/matrix.ts +0 -34
- package/src/channels/mattermost.ts +0 -57
- package/src/channels/msteams.ts +0 -33
- package/src/channels/nostr.ts +0 -33
- package/src/channels/qq.ts +0 -34
- package/src/channels/signal.ts +0 -33
- package/src/channels/slack.ts +0 -217
- package/src/channels/sms.ts +0 -34
- package/src/channels/telegram.ts +0 -616
- package/src/channels/twitch.ts +0 -65
- package/src/channels/voice-call.ts +0 -100
- package/src/channels/voice.ts +0 -471
- package/src/channels/web.ts +0 -632
- package/src/channels/webhook.ts +0 -199
- package/src/channels/websocket.ts +0 -399
- package/src/channels/wechat.ts +0 -329
- package/src/channels/whatsapp.ts +0 -33
- package/src/cli/chat.ts +0 -99
- package/src/cli/setup.ts +0 -314
- package/src/cli.ts +0 -2723
- package/src/core/a2a.ts +0 -203
- package/src/core/agent.ts +0 -476
- package/src/core/analytics-engine.ts +0 -186
- package/src/core/api-server.ts +0 -277
- package/src/core/audio.ts +0 -98
- package/src/core/auth.ts +0 -57
- package/src/core/cache.ts +0 -141
- package/src/core/collaboration.ts +0 -275
- package/src/core/compose.ts +0 -77
- package/src/core/config.ts +0 -14
- package/src/core/context-discovery.ts +0 -85
- package/src/core/context-refs.ts +0 -140
- package/src/core/errors.ts +0 -148
- package/src/core/gateway.ts +0 -106
- package/src/core/heartbeat.ts +0 -51
- package/src/core/hitl.ts +0 -138
- package/src/core/hooks.ts +0 -105
- package/src/core/ide-bridge.ts +0 -133
- package/src/core/knowledge.ts +0 -255
- package/src/core/logger.ts +0 -57
- package/src/core/node-network.ts +0 -86
- package/src/core/orchestrator.ts +0 -215
- package/src/core/performance.ts +0 -187
- package/src/core/profiles.ts +0 -122
- package/src/core/rate-limiter.ts +0 -128
- package/src/core/room.ts +0 -109
- package/src/core/runtime.ts +0 -410
- package/src/core/sandbox.ts +0 -344
- package/src/core/scheduler.ts +0 -187
- package/src/core/security.ts +0 -171
- package/src/core/session-manager.ts +0 -137
- package/src/core/streaming.ts +0 -195
- package/src/core/subagent.ts +0 -98
- package/src/core/types.ts +0 -68
- package/src/core/versioning.ts +0 -106
- package/src/core/vision.ts +0 -180
- package/src/core/watch.ts +0 -178
- package/src/core/workflow-graph.ts +0 -365
- package/src/core/workflow.ts +0 -235
- package/src/daemon.ts +0 -96
- package/src/deploy/hermes.ts +0 -156
- package/src/deploy/index.ts +0 -255
- package/src/deploy/openclaw.ts +0 -190
- package/src/doctor.ts +0 -156
- package/src/eval/index.ts +0 -211
- package/src/eval/suites/basic.json +0 -16
- package/src/eval/suites/memory.json +0 -12
- package/src/eval/suites/safety.json +0 -14
- package/src/hub/brain-seed.ts +0 -54
- package/src/hub/client.ts +0 -60
- package/src/i18n/index.ts +0 -216
- package/src/index.ts +0 -283
- package/src/mcp/servers/calculator-mcp.ts +0 -65
- package/src/mcp/servers/crypto-mcp.ts +0 -73
- package/src/mcp/servers/database-mcp.ts +0 -72
- package/src/mcp/servers/datetime-mcp.ts +0 -69
- package/src/mcp/servers/filesystem.ts +0 -66
- package/src/mcp/servers/github-mcp.ts +0 -58
- package/src/mcp/servers/index.ts +0 -63
- package/src/mcp/servers/json-mcp.ts +0 -102
- package/src/mcp/servers/memory-mcp.ts +0 -56
- package/src/mcp/servers/regex-mcp.ts +0 -53
- package/src/mcp/servers/web-mcp.ts +0 -49
- package/src/memory/context-compressor.ts +0 -189
- package/src/memory/deepbrain.ts +0 -108
- package/src/memory/index.ts +0 -41
- package/src/memory/seed-loader.ts +0 -212
- package/src/memory/user-profiler.ts +0 -215
- package/src/plugins/content-filter.ts +0 -23
- package/src/plugins/index.ts +0 -339
- package/src/plugins/logger.ts +0 -18
- package/src/plugins/rate-limiter.ts +0 -38
- package/src/protocols/a2a/client.ts +0 -132
- package/src/protocols/a2a/index.ts +0 -8
- package/src/protocols/a2a/server.ts +0 -333
- package/src/protocols/a2a/types.ts +0 -88
- package/src/protocols/a2a/utils.ts +0 -50
- package/src/protocols/agui/client.ts +0 -83
- package/src/protocols/agui/index.ts +0 -4
- package/src/protocols/agui/server.ts +0 -218
- package/src/protocols/agui/types.ts +0 -153
- package/src/protocols/index.ts +0 -2
- package/src/protocols/mcp/agent-tools.ts +0 -134
- package/src/protocols/mcp/index.ts +0 -8
- package/src/protocols/mcp/server.ts +0 -262
- package/src/protocols/mcp/types.ts +0 -69
- package/src/providers/index.ts +0 -632
- package/src/publish/index.ts +0 -376
- package/src/scheduler/cron-engine.ts +0 -191
- package/src/scheduler/index.ts +0 -2
- package/src/schema/oad.ts +0 -217
- package/src/security/approval.ts +0 -131
- package/src/security/approvals.ts +0 -143
- package/src/security/elevated.ts +0 -105
- package/src/security/guardrails.ts +0 -248
- package/src/security/index.ts +0 -9
- package/src/security/keys.ts +0 -87
- package/src/security/secrets.ts +0 -129
- package/src/skills/auto-learn.ts +0 -262
- package/src/skills/base.ts +0 -16
- package/src/skills/builtin/index.ts +0 -408
- package/src/skills/document.ts +0 -100
- package/src/skills/http.ts +0 -35
- package/src/skills/index.ts +0 -27
- package/src/skills/marketplace.ts +0 -113
- package/src/skills/scheduler.ts +0 -80
- package/src/skills/types.ts +0 -42
- package/src/skills/webhook-trigger.ts +0 -59
- package/src/studio/server.ts +0 -1791
- package/src/studio/templates-data.ts +0 -178
- package/src/studio-ui/index.html +0 -3076
- package/src/telemetry/index.ts +0 -324
- package/src/templates/code-reviewer.ts +0 -30
- package/src/templates/content-writer.ts +0 -58
- package/src/templates/customer-service.ts +0 -76
- package/src/templates/data-analyst.ts +0 -66
- package/src/templates/executive-assistant.ts +0 -71
- package/src/templates/financial-advisor.ts +0 -60
- package/src/templates/hr-recruiter.ts +0 -58
- package/src/templates/knowledge-base.ts +0 -27
- package/src/templates/legal-assistant.ts +0 -71
- package/src/templates/project-manager.ts +0 -58
- package/src/templates/sales-assistant.ts +0 -75
- package/src/templates/teacher.ts +0 -75
- package/src/testing/index.ts +0 -181
- package/src/tools/builtin/browser.ts +0 -299
- package/src/tools/builtin/datetime.ts +0 -41
- package/src/tools/builtin/file.ts +0 -107
- package/src/tools/builtin/home-assistant.ts +0 -116
- package/src/tools/builtin/index.ts +0 -37
- package/src/tools/builtin/rl-tools.ts +0 -243
- package/src/tools/builtin/shell.ts +0 -43
- package/src/tools/builtin/vision.ts +0 -64
- package/src/tools/builtin/web-search.ts +0 -126
- package/src/tools/builtin/web.ts +0 -35
- package/src/tools/calculator.ts +0 -73
- package/src/tools/datetime.ts +0 -149
- package/src/tools/document-processor.ts +0 -213
- package/src/tools/gateway.ts +0 -220
- package/src/tools/image-generator.ts +0 -150
- package/src/tools/integrations/calendar.ts +0 -73
- package/src/tools/integrations/code-exec.ts +0 -39
- package/src/tools/integrations/csv-analyzer.ts +0 -92
- package/src/tools/integrations/database.ts +0 -44
- package/src/tools/integrations/email-send.ts +0 -76
- package/src/tools/integrations/git-tool.ts +0 -42
- package/src/tools/integrations/github-tool.ts +0 -76
- package/src/tools/integrations/image-gen.ts +0 -56
- package/src/tools/integrations/index.ts +0 -92
- package/src/tools/integrations/jira.ts +0 -83
- package/src/tools/integrations/notion.ts +0 -71
- package/src/tools/integrations/npm-tool.ts +0 -48
- package/src/tools/integrations/pdf-reader.ts +0 -58
- package/src/tools/integrations/slack.ts +0 -65
- package/src/tools/integrations/summarizer.ts +0 -49
- package/src/tools/integrations/translator.ts +0 -48
- package/src/tools/integrations/trello.ts +0 -60
- package/src/tools/integrations/vector-search.ts +0 -42
- package/src/tools/integrations/web-scraper.ts +0 -47
- package/src/tools/integrations/web-search.ts +0 -58
- package/src/tools/integrations/webhook.ts +0 -38
- package/src/tools/json-transform.ts +0 -187
- package/src/tools/mcp-client.ts +0 -131
- package/src/tools/mcp.ts +0 -76
- package/src/tools/text-analysis.ts +0 -116
- package/src/tools/web-scraper.ts +0 -179
- package/src/tools/web-search.ts +0 -180
- package/src/traces/index.ts +0 -132
- package/src/types/agent-workstation.d.ts +0 -2
- package/src/ui/components.ts +0 -127
- package/srv-err.txt +0 -0
- package/srv-out.txt +0 -1
- package/test-agent/Dockerfile +0 -9
- package/test-agent/README.md +0 -50
- package/test-agent/agent.yaml +0 -23
- package/test-agent/docker-compose.yml +0 -11
- package/test-agent/oad.yaml +0 -31
- package/test-agent/package-lock.json +0 -1492
- package/test-agent/package.json +0 -18
- package/test-agent/src/index.ts +0 -24
- package/test-agent/src/skills/echo.ts +0 -15
- package/test-agent/tsconfig.json +0 -25
- package/test-full.js +0 -43
- package/test-sidebar.js +0 -22
- package/test-studio3.js +0 -75
- package/test-studio4.js +0 -41
- package/tests/a2a-protocol.test.ts +0 -285
- package/tests/a2a.test.ts +0 -66
- package/tests/agent.test.ts +0 -72
- package/tests/agui-protocol.test.ts +0 -246
- package/tests/analytics.test.ts +0 -50
- package/tests/api-server.test.ts +0 -148
- package/tests/approvals.test.ts +0 -89
- package/tests/audio.test.ts +0 -40
- package/tests/auto-learn.test.ts +0 -105
- package/tests/brain-seed-extended.test.ts +0 -490
- package/tests/brain-seed.test.ts +0 -239
- package/tests/browser.test.ts +0 -179
- package/tests/builtin-tools.test.ts +0 -83
- package/tests/channel.test.ts +0 -39
- package/tests/channels/discord.test.ts +0 -79
- package/tests/channels/email.test.ts +0 -148
- package/tests/channels/feishu.test.ts +0 -123
- package/tests/channels/telegram.test.ts +0 -129
- package/tests/channels/websocket.test.ts +0 -53
- package/tests/channels/wechat.test.ts +0 -170
- package/tests/channels-extra.test.ts +0 -45
- package/tests/chat-cli.test.ts +0 -160
- package/tests/cli.test.ts +0 -46
- package/tests/collaboration.test.ts +0 -319
- package/tests/context-compressor.test.ts +0 -172
- package/tests/context-refs.test.ts +0 -121
- package/tests/cron-engine.test.ts +0 -101
- package/tests/daemon.test.ts +0 -135
- package/tests/deepbrain-wire.test.ts +0 -234
- package/tests/deploy-and-dag.test.ts +0 -196
- package/tests/doctor.test.ts +0 -38
- package/tests/document-processor.test.ts +0 -69
- package/tests/e2e-nocode.test.ts +0 -442
- package/tests/e2e.test.ts +0 -134
- package/tests/elevated.test.ts +0 -69
- package/tests/errors.test.ts +0 -83
- package/tests/eval.test.ts +0 -173
- package/tests/gateway.test.ts +0 -63
- package/tests/guardrails.test.ts +0 -177
- package/tests/hitl.test.ts +0 -71
- package/tests/home-assistant.test.ts +0 -40
- package/tests/hooks.test.ts +0 -79
- package/tests/i18n.test.ts +0 -41
- package/tests/ide-bridge.test.ts +0 -38
- package/tests/image-generator.test.ts +0 -84
- package/tests/init-role.test.ts +0 -124
- package/tests/integrations.test.ts +0 -249
- package/tests/mcp-client.test.ts +0 -92
- package/tests/mcp-server.test.ts +0 -178
- package/tests/mcp-servers.test.ts +0 -260
- package/tests/mcp.test.ts +0 -54
- package/tests/node-network.test.ts +0 -74
- package/tests/oad.test.ts +0 -68
- package/tests/performance.test.ts +0 -115
- package/tests/plugin-a2a-enhanced.test.ts +0 -230
- package/tests/plugin.test.ts +0 -74
- package/tests/profiles.test.ts +0 -61
- package/tests/publish.test.ts +0 -231
- package/tests/rl-tools.test.ts +0 -93
- package/tests/room.test.ts +0 -106
- package/tests/runtime.test.ts +0 -42
- package/tests/sandbox-manager.test.ts +0 -46
- package/tests/sandbox.test.ts +0 -46
- package/tests/scheduler.test.ts +0 -200
- package/tests/secrets.test.ts +0 -107
- package/tests/security-enhanced.test.ts +0 -233
- package/tests/security.test.ts +0 -60
- package/tests/settings-api.test.ts +0 -148
- package/tests/setup.test.ts +0 -73
- package/tests/skill-learner.test.ts +0 -161
- package/tests/streaming.test.ts +0 -109
- package/tests/studio.test.ts +0 -402
- package/tests/subagent.test.ts +0 -193
- package/tests/telegram-discord.test.ts +0 -60
- package/tests/telemetry.test.ts +0 -186
- package/tests/templates.test.ts +0 -77
- package/tests/tools/builtin-extended.test.ts +0 -138
- package/tests/user-profiler.test.ts +0 -169
- package/tests/v070.test.ts +0 -76
- package/tests/v090-features.test.ts +0 -254
- package/tests/versioning.test.ts +0 -75
- package/tests/vision.test.ts +0 -61
- package/tests/voice-call.test.ts +0 -47
- package/tests/voice-enhanced.test.ts +0 -169
- package/tests/voice-interaction.test.ts +0 -38
- package/tests/voice.test.ts +0 -61
- package/tests/web-search.test.ts +0 -155
- package/tests/webhook.test.ts +0 -29
- package/tests/workflow-graph.test.ts +0 -279
- package/tests/workflow.test.ts +0 -143
- package/tmp-js-test.js +0 -1532
- package/tmp-sc.js +0 -1716
- package/tutorial/customer-service-agent/README.md +0 -612
- package/tutorial/customer-service-agent/SOUL.md +0 -26
- package/tutorial/customer-service-agent/agent.yaml +0 -63
- package/tutorial/customer-service-agent/package.json +0 -19
- package/tutorial/customer-service-agent/src/index.ts +0 -69
- package/tutorial/customer-service-agent/src/skills/faq.ts +0 -27
- package/tutorial/customer-service-agent/src/skills/ticket.ts +0 -22
- package/tutorial/customer-service-agent/tsconfig.json +0 -14
- package/vitest.config.ts +0 -9
package/src/channels/telegram.ts
DELETED
|
@@ -1,616 +0,0 @@
|
|
|
1
|
-
import type { Message } from '../core/types';
|
|
2
|
-
import { BaseChannel } from './index';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Telegram channel — production-quality Telegram bot integration.
|
|
6
|
-
*
|
|
7
|
-
* Features (aligned with OpenClaw):
|
|
8
|
-
* - Live stream preview (sendMessage + editMessageText)
|
|
9
|
-
* - Ack reaction on message receipt
|
|
10
|
-
* - Typing indicator throughout processing
|
|
11
|
-
* - HTML parse mode with Markdown fallback
|
|
12
|
-
* - Smart text chunking (paragraph-aware)
|
|
13
|
-
* - /start, /help, /status commands
|
|
14
|
-
* - Photo/document caption handling
|
|
15
|
-
* - Callback query (inline button) support
|
|
16
|
-
* - Reply threading
|
|
17
|
-
* - Error recovery with plain-text fallback
|
|
18
|
-
* - Forum topic support
|
|
19
|
-
* - Group mention filtering
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
export interface TelegramChannelConfig {
|
|
23
|
-
token?: string;
|
|
24
|
-
mode?: 'polling' | 'webhook';
|
|
25
|
-
webhookUrl?: string;
|
|
26
|
-
webhookSecret?: string;
|
|
27
|
-
port?: number;
|
|
28
|
-
// Feature flags
|
|
29
|
-
streaming?: boolean | 'off' | 'partial';
|
|
30
|
-
ackReaction?: string; // emoji to react with on receipt, e.g. "👀"
|
|
31
|
-
linkPreview?: boolean;
|
|
32
|
-
textChunkLimit?: number;
|
|
33
|
-
requireMention?: boolean; // for groups
|
|
34
|
-
botUsername?: string; // for mention detection
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export class TelegramChannel extends BaseChannel {
|
|
38
|
-
readonly type = 'telegram';
|
|
39
|
-
private token: string;
|
|
40
|
-
private mode: 'polling' | 'webhook';
|
|
41
|
-
private webhookUrl?: string;
|
|
42
|
-
private webhookSecret?: string;
|
|
43
|
-
private port: number;
|
|
44
|
-
private botUsername: string = '';
|
|
45
|
-
private botInfo: any = null;
|
|
46
|
-
|
|
47
|
-
// Config
|
|
48
|
-
private streamingEnabled: boolean;
|
|
49
|
-
private ackReaction: string;
|
|
50
|
-
private linkPreview: boolean;
|
|
51
|
-
private textChunkLimit: number;
|
|
52
|
-
private requireMention: boolean;
|
|
53
|
-
|
|
54
|
-
// Polling state
|
|
55
|
-
private offset: number = 0;
|
|
56
|
-
private polling: boolean = false;
|
|
57
|
-
|
|
58
|
-
// Webhook state
|
|
59
|
-
private server: import('http').Server | null = null;
|
|
60
|
-
|
|
61
|
-
// Stream handler — set by runtime when provider supports streaming
|
|
62
|
-
private streamHandler?: (msg: Message) => AsyncIterable<string>;
|
|
63
|
-
|
|
64
|
-
constructor(config: TelegramChannelConfig = {}) {
|
|
65
|
-
super();
|
|
66
|
-
this.token = config.token ?? process.env.TELEGRAM_BOT_TOKEN ?? '';
|
|
67
|
-
this.mode = config.mode ?? 'polling';
|
|
68
|
-
this.webhookUrl = config.webhookUrl;
|
|
69
|
-
this.webhookSecret = config.webhookSecret;
|
|
70
|
-
this.port = config.port ?? 3001;
|
|
71
|
-
|
|
72
|
-
// Feature config
|
|
73
|
-
this.streamingEnabled = config.streaming !== false && config.streaming !== 'off';
|
|
74
|
-
this.ackReaction = config.ackReaction ?? '👀';
|
|
75
|
-
this.linkPreview = config.linkPreview ?? true;
|
|
76
|
-
this.textChunkLimit = config.textChunkLimit ?? 4000;
|
|
77
|
-
this.requireMention = config.requireMention ?? false;
|
|
78
|
-
if (config.botUsername) this.botUsername = config.botUsername.replace('@', '').toLowerCase();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
setStreamHandler(handler: (msg: Message) => AsyncIterable<string>): void {
|
|
82
|
-
this.streamHandler = handler;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async start(): Promise<void> {
|
|
86
|
-
if (!this.token) {
|
|
87
|
-
console.warn('[TelegramChannel] No bot token provided. Set TELEGRAM_BOT_TOKEN or pass token in config.');
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Fetch bot info for username detection
|
|
92
|
-
try {
|
|
93
|
-
const me = await this.apiCall('getMe');
|
|
94
|
-
if (me?.result) {
|
|
95
|
-
this.botInfo = me.result;
|
|
96
|
-
this.botUsername = (me.result.username ?? '').toLowerCase();
|
|
97
|
-
console.log(`[TelegramChannel] Bot: @${this.botUsername}`);
|
|
98
|
-
}
|
|
99
|
-
} catch {}
|
|
100
|
-
|
|
101
|
-
if (this.mode === 'webhook') {
|
|
102
|
-
await this.startWebhook();
|
|
103
|
-
} else {
|
|
104
|
-
await this.startPolling();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async stop(): Promise<void> {
|
|
109
|
-
if (this.mode === 'webhook') {
|
|
110
|
-
await this.stopWebhook();
|
|
111
|
-
} else {
|
|
112
|
-
this.polling = false;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// ─── Polling Mode ────────────────────────────────────────
|
|
117
|
-
|
|
118
|
-
private async startPolling(): Promise<void> {
|
|
119
|
-
await this.apiCall('deleteWebhook');
|
|
120
|
-
console.log(`[TelegramChannel] Started long-polling mode`);
|
|
121
|
-
this.polling = true;
|
|
122
|
-
this.poll();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
private async poll(): Promise<void> {
|
|
126
|
-
while (this.polling) {
|
|
127
|
-
try {
|
|
128
|
-
const updates = await this.getUpdates();
|
|
129
|
-
for (const update of updates) {
|
|
130
|
-
// Don't await — process concurrently for better responsiveness
|
|
131
|
-
this.processUpdate(update).catch((err) => {
|
|
132
|
-
console.error('[TelegramChannel] Update processing error:', err);
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
} catch (err) {
|
|
136
|
-
console.error('[TelegramChannel] Polling error:', err);
|
|
137
|
-
if (this.polling) {
|
|
138
|
-
await new Promise((r) => setTimeout(r, 5000));
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
private async getUpdates(): Promise<any[]> {
|
|
145
|
-
const url = `https://api.telegram.org/bot${this.token}/getUpdates?offset=${this.offset}&timeout=30&allowed_updates=${encodeURIComponent('["message","callback_query","message_reaction"]')}`;
|
|
146
|
-
const controller = new AbortController();
|
|
147
|
-
const timeout = setTimeout(() => controller.abort(), 40000);
|
|
148
|
-
|
|
149
|
-
try {
|
|
150
|
-
const res = await fetch(url, { signal: controller.signal });
|
|
151
|
-
const data = (await res.json()) as { ok: boolean; result: any[] };
|
|
152
|
-
if (data.ok && data.result.length > 0) {
|
|
153
|
-
this.offset = data.result[data.result.length - 1].update_id + 1;
|
|
154
|
-
}
|
|
155
|
-
return data.result || [];
|
|
156
|
-
} finally {
|
|
157
|
-
clearTimeout(timeout);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// ─── Webhook Mode ────────────────────────────────────────
|
|
162
|
-
|
|
163
|
-
private async startWebhook(): Promise<void> {
|
|
164
|
-
if (this.webhookUrl) {
|
|
165
|
-
const params: Record<string, unknown> = {
|
|
166
|
-
url: `${this.webhookUrl}/webhook/${this.token}`,
|
|
167
|
-
allowed_updates: ['message', 'callback_query', 'message_reaction'],
|
|
168
|
-
};
|
|
169
|
-
if (this.webhookSecret) params.secret_token = this.webhookSecret;
|
|
170
|
-
await this.apiCall('setWebhook', params);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const express = (await import('express')).default;
|
|
174
|
-
const app = express();
|
|
175
|
-
app.use(express.json());
|
|
176
|
-
|
|
177
|
-
app.post(`/webhook/${this.token}`, async (req, res) => {
|
|
178
|
-
// Verify secret if configured
|
|
179
|
-
if (this.webhookSecret && req.headers['x-telegram-bot-api-secret-token'] !== this.webhookSecret) {
|
|
180
|
-
res.status(403).json({ error: 'Forbidden' });
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
try {
|
|
184
|
-
// Don't await — respond quickly, process in background
|
|
185
|
-
this.processUpdate(req.body).catch((err) => {
|
|
186
|
-
console.error('[TelegramChannel] Webhook processing error:', err);
|
|
187
|
-
});
|
|
188
|
-
res.json({ ok: true });
|
|
189
|
-
} catch (err) {
|
|
190
|
-
console.error('[TelegramChannel] Webhook error:', err);
|
|
191
|
-
res.status(500).json({ error: 'Internal error' });
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
app.get('/health', (_req, res) => {
|
|
196
|
-
res.json({ status: 'ok', channel: 'telegram', mode: 'webhook', bot: this.botUsername });
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
return new Promise((resolve) => {
|
|
200
|
-
this.server = app.listen(this.port, () => {
|
|
201
|
-
console.log(`[TelegramChannel] Webhook server on port ${this.port}`);
|
|
202
|
-
resolve();
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
private async stopWebhook(): Promise<void> {
|
|
208
|
-
return new Promise((resolve, reject) => {
|
|
209
|
-
if (!this.server) return resolve();
|
|
210
|
-
this.server.close((err) => (err ? reject(err) : resolve()));
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// ─── Update Processing ──────────────────────────────────
|
|
215
|
-
|
|
216
|
-
private async processUpdate(update: any): Promise<void> {
|
|
217
|
-
// Handle callback queries (inline buttons)
|
|
218
|
-
if (update.callback_query) {
|
|
219
|
-
await this.handleCallbackQuery(update.callback_query);
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const message = update.message || update.edited_message;
|
|
224
|
-
if (!message || !this.handler) return;
|
|
225
|
-
|
|
226
|
-
// Handle commands
|
|
227
|
-
if (message.text?.startsWith('/')) {
|
|
228
|
-
const handled = await this.handleCommand(message);
|
|
229
|
-
if (handled) return;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Extract text from various message types
|
|
233
|
-
const text = message.text || message.caption;
|
|
234
|
-
if (!text) return;
|
|
235
|
-
|
|
236
|
-
// Group mention filtering
|
|
237
|
-
if (this.isGroupChat(message) && this.requireMention) {
|
|
238
|
-
if (!this.isMentioned(text)) return;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// Build message object
|
|
242
|
-
const msg: Message = {
|
|
243
|
-
id: `tg_${message.message_id}`,
|
|
244
|
-
role: 'user',
|
|
245
|
-
content: text,
|
|
246
|
-
timestamp: message.date * 1000,
|
|
247
|
-
metadata: {
|
|
248
|
-
sessionId: this.getSessionId(message),
|
|
249
|
-
chatId: message.chat.id,
|
|
250
|
-
userId: message.from?.id,
|
|
251
|
-
username: message.from?.username,
|
|
252
|
-
firstName: message.from?.first_name,
|
|
253
|
-
lastName: message.from?.last_name,
|
|
254
|
-
platform: 'telegram',
|
|
255
|
-
chatType: message.chat.type,
|
|
256
|
-
messageThreadId: message.message_thread_id,
|
|
257
|
-
replyToMessageId: message.message_id,
|
|
258
|
-
},
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
// Ack reaction — immediate visual feedback
|
|
262
|
-
if (this.ackReaction) {
|
|
263
|
-
this.setReaction(message.chat.id, message.message_id, this.ackReaction).catch(() => {});
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// Typing indicator
|
|
267
|
-
const threadId = message.message_thread_id;
|
|
268
|
-
await this.sendTyping(message.chat.id, threadId);
|
|
269
|
-
const typingInterval = setInterval(() => {
|
|
270
|
-
this.sendTyping(message.chat.id, threadId).catch(() => {});
|
|
271
|
-
}, 4000);
|
|
272
|
-
|
|
273
|
-
try {
|
|
274
|
-
if (this.streamingEnabled && this.streamHandler) {
|
|
275
|
-
await this.streamResponse(message.chat.id, msg, message.message_id, threadId);
|
|
276
|
-
} else {
|
|
277
|
-
const response = await this.handler(msg);
|
|
278
|
-
await this.sendFormattedMessage(message.chat.id, response.content, message.message_id, threadId);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// Remove ack reaction after successful response
|
|
282
|
-
if (this.ackReaction) {
|
|
283
|
-
this.setReaction(message.chat.id, message.message_id, '').catch(() => {});
|
|
284
|
-
}
|
|
285
|
-
} catch (err) {
|
|
286
|
-
console.error('[TelegramChannel] Error processing message:', err);
|
|
287
|
-
await this.sendFormattedMessage(message.chat.id, '⚠️ Sorry, something went wrong. Please try again.', message.message_id, threadId);
|
|
288
|
-
} finally {
|
|
289
|
-
clearInterval(typingInterval);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
// ─── Commands ───────────────────────────────────────────
|
|
294
|
-
|
|
295
|
-
private async handleCommand(message: any): Promise<boolean> {
|
|
296
|
-
const text = message.text ?? '';
|
|
297
|
-
const command = text.split(' ')[0].split('@')[0].toLowerCase(); // Strip @botname
|
|
298
|
-
|
|
299
|
-
switch (command) {
|
|
300
|
-
case '/start':
|
|
301
|
-
await this.sendFormattedMessage(
|
|
302
|
-
message.chat.id,
|
|
303
|
-
`👋 <b>Hello${message.from?.first_name ? ' ' + this.escapeHtml(message.from.first_name) : ''}!</b>\n\nI'm ready to help. Send me a message to get started.\n\nCommands:\n/help — Show available commands\n/status — Check bot status`,
|
|
304
|
-
undefined,
|
|
305
|
-
message.message_thread_id
|
|
306
|
-
);
|
|
307
|
-
return true;
|
|
308
|
-
|
|
309
|
-
case '/help':
|
|
310
|
-
await this.sendFormattedMessage(
|
|
311
|
-
message.chat.id,
|
|
312
|
-
`📖 <b>Available Commands</b>\n\n/start — Start conversation\n/help — Show this help\n/status — Bot status\n\nJust send a message and I'll respond!`,
|
|
313
|
-
undefined,
|
|
314
|
-
message.message_thread_id
|
|
315
|
-
);
|
|
316
|
-
return true;
|
|
317
|
-
|
|
318
|
-
case '/status':
|
|
319
|
-
const uptime = process.uptime();
|
|
320
|
-
const hours = Math.floor(uptime / 3600);
|
|
321
|
-
const mins = Math.floor((uptime % 3600) / 60);
|
|
322
|
-
await this.sendFormattedMessage(
|
|
323
|
-
message.chat.id,
|
|
324
|
-
`🟢 <b>Bot Status</b>\n\n⏱ Uptime: ${hours}h ${mins}m\n🤖 Bot: @${this.botUsername}\n💬 Mode: ${this.mode}\n📡 Streaming: ${this.streamingEnabled ? 'on' : 'off'}`,
|
|
325
|
-
undefined,
|
|
326
|
-
message.message_thread_id
|
|
327
|
-
);
|
|
328
|
-
return true;
|
|
329
|
-
|
|
330
|
-
default:
|
|
331
|
-
return false; // Not a recognized command, let it flow through as normal message
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// ─── Callback Queries (Inline Buttons) ──────────────────
|
|
336
|
-
|
|
337
|
-
private async handleCallbackQuery(query: any): Promise<void> {
|
|
338
|
-
// Answer the callback to remove loading state
|
|
339
|
-
await this.apiCall('answerCallbackQuery', { callback_query_id: query.id });
|
|
340
|
-
|
|
341
|
-
if (!this.handler || !query.data) return;
|
|
342
|
-
|
|
343
|
-
const msg: Message = {
|
|
344
|
-
id: `tg_cb_${query.id}`,
|
|
345
|
-
role: 'user',
|
|
346
|
-
content: `callback_data: ${query.data}`,
|
|
347
|
-
timestamp: Date.now(),
|
|
348
|
-
metadata: {
|
|
349
|
-
sessionId: `tg_${query.message?.chat?.id ?? query.from.id}`,
|
|
350
|
-
chatId: query.message?.chat?.id ?? query.from.id,
|
|
351
|
-
userId: query.from.id,
|
|
352
|
-
username: query.from.username,
|
|
353
|
-
firstName: query.from.first_name,
|
|
354
|
-
platform: 'telegram',
|
|
355
|
-
chatType: query.message?.chat?.type ?? 'private',
|
|
356
|
-
isCallback: true,
|
|
357
|
-
},
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
try {
|
|
361
|
-
const response = await this.handler(msg);
|
|
362
|
-
const chatId = query.message?.chat?.id ?? query.from.id;
|
|
363
|
-
await this.sendFormattedMessage(chatId, response.content);
|
|
364
|
-
} catch (err) {
|
|
365
|
-
console.error('[TelegramChannel] Callback query error:', err);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// ─── Streaming ──────────────────────────────────────────
|
|
370
|
-
|
|
371
|
-
private async streamResponse(chatId: number | string, msg: Message, replyTo?: number, threadId?: number): Promise<void> {
|
|
372
|
-
if (!this.streamHandler) return;
|
|
373
|
-
|
|
374
|
-
let sentMessageId: number | null = null;
|
|
375
|
-
let fullText = '';
|
|
376
|
-
let lastEditTime = 0;
|
|
377
|
-
const EDIT_INTERVAL = 800; // Edit slightly faster than before
|
|
378
|
-
const MIN_FIRST_SEND = 20; // Min chars before first send (avoid tiny initial message)
|
|
379
|
-
|
|
380
|
-
const doEdit = async (final: boolean = false) => {
|
|
381
|
-
if (!sentMessageId || !fullText) return;
|
|
382
|
-
const displayText = final ? fullText : fullText + ' ▍'; // Cursor indicator while streaming
|
|
383
|
-
try {
|
|
384
|
-
await this.apiCall('editMessageText', {
|
|
385
|
-
chat_id: chatId,
|
|
386
|
-
message_id: sentMessageId,
|
|
387
|
-
text: displayText,
|
|
388
|
-
parse_mode: 'HTML',
|
|
389
|
-
disable_web_page_preview: !this.linkPreview,
|
|
390
|
-
});
|
|
391
|
-
lastEditTime = Date.now();
|
|
392
|
-
} catch {
|
|
393
|
-
// HTML parse failed, try plain text
|
|
394
|
-
try {
|
|
395
|
-
await this.apiCall('editMessageText', {
|
|
396
|
-
chat_id: chatId,
|
|
397
|
-
message_id: sentMessageId,
|
|
398
|
-
text: displayText,
|
|
399
|
-
});
|
|
400
|
-
lastEditTime = Date.now();
|
|
401
|
-
} catch {}
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
|
|
405
|
-
try {
|
|
406
|
-
for await (const chunk of this.streamHandler(msg)) {
|
|
407
|
-
fullText += chunk;
|
|
408
|
-
|
|
409
|
-
if (!sentMessageId && fullText.length >= MIN_FIRST_SEND) {
|
|
410
|
-
const result = await this.sendFormattedMessage(chatId, fullText + ' ▍', replyTo, threadId);
|
|
411
|
-
sentMessageId = result?.message_id;
|
|
412
|
-
lastEditTime = Date.now();
|
|
413
|
-
} else if (sentMessageId) {
|
|
414
|
-
const now = Date.now();
|
|
415
|
-
if (now - lastEditTime >= EDIT_INTERVAL) {
|
|
416
|
-
await doEdit();
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
// Final edit — remove cursor, clean formatting
|
|
422
|
-
if (sentMessageId && fullText) {
|
|
423
|
-
await doEdit(true);
|
|
424
|
-
} else if (!sentMessageId && fullText) {
|
|
425
|
-
// Never sent first message (very short response)
|
|
426
|
-
await this.sendFormattedMessage(chatId, fullText, replyTo, threadId);
|
|
427
|
-
}
|
|
428
|
-
} catch (err) {
|
|
429
|
-
if (!sentMessageId && fullText) {
|
|
430
|
-
await this.sendFormattedMessage(chatId, fullText, replyTo, threadId);
|
|
431
|
-
}
|
|
432
|
-
throw err;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
// ─── Message Sending ───────────────────────────────────
|
|
437
|
-
|
|
438
|
-
async sendFormattedMessage(chatId: number | string, text: string, replyTo?: number, threadId?: number): Promise<any> {
|
|
439
|
-
const chunks = this.smartSplit(text, this.textChunkLimit);
|
|
440
|
-
let lastResult: any = null;
|
|
441
|
-
|
|
442
|
-
for (const chunk of chunks) {
|
|
443
|
-
const baseParams: Record<string, unknown> = {
|
|
444
|
-
chat_id: chatId,
|
|
445
|
-
disable_web_page_preview: !this.linkPreview,
|
|
446
|
-
...(replyTo ? { reply_to_message_id: replyTo } : {}),
|
|
447
|
-
...(threadId ? { message_thread_id: threadId } : {}),
|
|
448
|
-
};
|
|
449
|
-
|
|
450
|
-
// Try HTML first (richer formatting)
|
|
451
|
-
try {
|
|
452
|
-
const htmlText = this.markdownToHtml(chunk);
|
|
453
|
-
lastResult = await this.apiCall('sendMessage', {
|
|
454
|
-
...baseParams,
|
|
455
|
-
text: htmlText,
|
|
456
|
-
parse_mode: 'HTML',
|
|
457
|
-
});
|
|
458
|
-
} catch {
|
|
459
|
-
// HTML failed, try Markdown
|
|
460
|
-
try {
|
|
461
|
-
lastResult = await this.apiCall('sendMessage', {
|
|
462
|
-
...baseParams,
|
|
463
|
-
text: chunk,
|
|
464
|
-
parse_mode: 'Markdown',
|
|
465
|
-
});
|
|
466
|
-
} catch {
|
|
467
|
-
// All parsing failed, send plain text
|
|
468
|
-
lastResult = await this.apiCall('sendMessage', {
|
|
469
|
-
...baseParams,
|
|
470
|
-
text: chunk,
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
// Only reply to first chunk
|
|
476
|
-
replyTo = undefined;
|
|
477
|
-
}
|
|
478
|
-
return lastResult?.result;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
async sendMessage(chatId: number | string, text: string): Promise<void> {
|
|
482
|
-
await this.sendFormattedMessage(chatId, text);
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
// ─── Reactions ──────────────────────────────────────────
|
|
486
|
-
|
|
487
|
-
private async setReaction(chatId: number | string, messageId: number, emoji: string): Promise<void> {
|
|
488
|
-
try {
|
|
489
|
-
await this.apiCall('setMessageReaction', {
|
|
490
|
-
chat_id: chatId,
|
|
491
|
-
message_id: messageId,
|
|
492
|
-
reaction: emoji ? [{ type: 'emoji', emoji }] : [],
|
|
493
|
-
});
|
|
494
|
-
} catch {
|
|
495
|
-
// Reactions may not be available in all chats
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
// ─── Typing ─────────────────────────────────────────────
|
|
500
|
-
|
|
501
|
-
private async sendTyping(chatId: number | string, threadId?: number): Promise<void> {
|
|
502
|
-
await this.apiCall('sendChatAction', {
|
|
503
|
-
chat_id: chatId,
|
|
504
|
-
action: 'typing',
|
|
505
|
-
...(threadId ? { message_thread_id: threadId } : {}),
|
|
506
|
-
}).catch(() => {});
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
// ─── Helpers ────────────────────────────────────────────
|
|
510
|
-
|
|
511
|
-
private isGroupChat(message: any): boolean {
|
|
512
|
-
return message.chat.type === 'group' || message.chat.type === 'supergroup';
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
private isMentioned(text: string): boolean {
|
|
516
|
-
if (!this.botUsername) return true;
|
|
517
|
-
const lower = text.toLowerCase();
|
|
518
|
-
return lower.includes(`@${this.botUsername}`);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
private getSessionId(message: any): string {
|
|
522
|
-
const chatId = message.chat.id;
|
|
523
|
-
const threadId = message.message_thread_id;
|
|
524
|
-
if (threadId && message.chat.is_forum) {
|
|
525
|
-
return `tg_${chatId}_topic_${threadId}`;
|
|
526
|
-
}
|
|
527
|
-
return `tg_${chatId}`;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
private escapeHtml(text: string): string {
|
|
531
|
-
return text
|
|
532
|
-
.replace(/&/g, '&')
|
|
533
|
-
.replace(/</g, '<')
|
|
534
|
-
.replace(/>/g, '>')
|
|
535
|
-
.replace(/"/g, '"');
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* Convert basic Markdown to Telegram-safe HTML.
|
|
540
|
-
* Handles: bold, italic, code, code blocks, links.
|
|
541
|
-
*/
|
|
542
|
-
private markdownToHtml(text: string): string {
|
|
543
|
-
let html = this.escapeHtml(text);
|
|
544
|
-
|
|
545
|
-
// Code blocks (```...```)
|
|
546
|
-
html = html.replace(/```(\w*)\n?([\s\S]*?)```/g, (_m, lang, code) => {
|
|
547
|
-
return `<pre${lang ? ` class="language-${lang}"` : ''}>${code}</pre>`;
|
|
548
|
-
});
|
|
549
|
-
|
|
550
|
-
// Inline code (`...`)
|
|
551
|
-
html = html.replace(/`([^`]+)`/g, '<code>$1</code>');
|
|
552
|
-
|
|
553
|
-
// Bold (**...**)
|
|
554
|
-
html = html.replace(/\*\*(.+?)\*\*/g, '<b>$1</b>');
|
|
555
|
-
|
|
556
|
-
// Italic (*...*)
|
|
557
|
-
html = html.replace(/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g, '<i>$1</i>');
|
|
558
|
-
|
|
559
|
-
// Links [text](url)
|
|
560
|
-
html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>');
|
|
561
|
-
|
|
562
|
-
return html;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
/**
|
|
566
|
-
* Smart text splitting — prefer paragraph boundaries (blank lines) before hard length split.
|
|
567
|
-
* Aligned with OpenClaw's chunkMode="newline" behavior.
|
|
568
|
-
*/
|
|
569
|
-
private smartSplit(text: string, maxLen: number): string[] {
|
|
570
|
-
if (text.length <= maxLen) return [text];
|
|
571
|
-
|
|
572
|
-
const parts: string[] = [];
|
|
573
|
-
let remaining = text;
|
|
574
|
-
|
|
575
|
-
while (remaining.length > maxLen) {
|
|
576
|
-
// Try to find a paragraph break (double newline) near the limit
|
|
577
|
-
let splitAt = remaining.lastIndexOf('\n\n', maxLen);
|
|
578
|
-
if (splitAt < maxLen * 0.3) {
|
|
579
|
-
// No good paragraph break, try single newline
|
|
580
|
-
splitAt = remaining.lastIndexOf('\n', maxLen);
|
|
581
|
-
}
|
|
582
|
-
if (splitAt < maxLen * 0.3) {
|
|
583
|
-
// No good newline, hard split at limit
|
|
584
|
-
splitAt = maxLen;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
parts.push(remaining.slice(0, splitAt).trimEnd());
|
|
588
|
-
remaining = remaining.slice(splitAt).trimStart();
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
if (remaining) parts.push(remaining);
|
|
592
|
-
return parts;
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
private async apiCall(method: string, body?: Record<string, unknown>): Promise<any> {
|
|
596
|
-
const url = `https://api.telegram.org/bot${this.token}/${method}`;
|
|
597
|
-
try {
|
|
598
|
-
const res = await fetch(url, {
|
|
599
|
-
method: 'POST',
|
|
600
|
-
headers: { 'Content-Type': 'application/json' },
|
|
601
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
602
|
-
});
|
|
603
|
-
const data = await res.json() as { ok: boolean; result?: any; description?: string };
|
|
604
|
-
if (!data.ok) {
|
|
605
|
-
const err = new Error(`Telegram API ${method} failed: ${data.description}`);
|
|
606
|
-
(err as any).telegramError = data;
|
|
607
|
-
throw err;
|
|
608
|
-
}
|
|
609
|
-
return data;
|
|
610
|
-
} catch (err) {
|
|
611
|
-
if ((err as any).telegramError) throw err;
|
|
612
|
-
console.error(`[TelegramChannel] API call ${method} failed:`, err);
|
|
613
|
-
throw err;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
}
|
package/src/channels/twitch.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { BaseChannel } from './index';
|
|
2
|
-
import type { Message } from '../core/types';
|
|
3
|
-
|
|
4
|
-
export interface TwitchChannelConfig {
|
|
5
|
-
username: string;
|
|
6
|
-
oauthToken: string;
|
|
7
|
-
channels: string[];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class TwitchChannel extends BaseChannel {
|
|
11
|
-
readonly type = 'twitch';
|
|
12
|
-
private config: TwitchChannelConfig;
|
|
13
|
-
private client: any = null;
|
|
14
|
-
private running = false;
|
|
15
|
-
|
|
16
|
-
constructor(config: TwitchChannelConfig) {
|
|
17
|
-
super();
|
|
18
|
-
if (!config.username || !config.oauthToken || !config.channels?.length) {
|
|
19
|
-
throw new Error('TwitchChannel requires username, oauthToken, and channels in config');
|
|
20
|
-
}
|
|
21
|
-
this.config = config;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async start(): Promise<void> {
|
|
25
|
-
let tmi: any;
|
|
26
|
-
try {
|
|
27
|
-
tmi = require('tmi.js');
|
|
28
|
-
} catch {
|
|
29
|
-
throw new Error('Install tmi.js to use the TwitchChannel. Run: npm install tmi.js');
|
|
30
|
-
}
|
|
31
|
-
this.client = new tmi.Client({
|
|
32
|
-
identity: { username: this.config.username, password: this.config.oauthToken },
|
|
33
|
-
channels: this.config.channels,
|
|
34
|
-
});
|
|
35
|
-
await this.client.connect();
|
|
36
|
-
this.running = true;
|
|
37
|
-
|
|
38
|
-
this.client.on('message', async (channel: string, tags: any, message: string, self: boolean) => {
|
|
39
|
-
if (self || !this.handler) return;
|
|
40
|
-
const msg: Message = {
|
|
41
|
-
id: tags.id || Date.now().toString(),
|
|
42
|
-
role: 'user',
|
|
43
|
-
content: message,
|
|
44
|
-
timestamp: Date.now(),
|
|
45
|
-
metadata: { channel, username: tags.username, tags },
|
|
46
|
-
};
|
|
47
|
-
await this.handler(msg);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async stop(): Promise<void> {
|
|
52
|
-
if (this.client) {
|
|
53
|
-
await this.client.disconnect();
|
|
54
|
-
this.client = null;
|
|
55
|
-
}
|
|
56
|
-
this.running = false;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async send(channel: string, text: string): Promise<void> {
|
|
60
|
-
if (!this.running || !this.client) {
|
|
61
|
-
throw new Error('TwitchChannel: not started. Call start() first.');
|
|
62
|
-
}
|
|
63
|
-
await this.client.say(channel, text);
|
|
64
|
-
}
|
|
65
|
-
}
|