gtc setup
gtc setup 命令用于配置你的 Greentic bundle 中的 providers。它会为每个启用的 provider 运行 setup flows,收集凭据并配置 webhooks。
gtc setup [OPTIONS] <BUNDLE_PATH>| 选项 | 说明 |
|---|---|
--answers <FILE> | answers 文件路径(非交互模式) |
--dry-run | 预览 setup 而不做任何更改 |
--emit-answers <FILE> | 生成 answers 模板 |
--advanced | 在 answers 模板中包含可选字段 |
--provider <NAME> | 仅设置指定 provider |
--skip <NAME> | 跳过指定 provider |
-v, --verbose | 启用详细输出 |
以交互方式运行 setup,CLI 会依次提示你配置每个 provider:
gtc setup ./my-bundleCLI 会提示输入:
- Provider 凭据(API keys、tokens)
- 用于 webhooks 的公开 URL
- 可选配置项
非交互式设置
Section titled “非交互式设置”生成 Answers 模板
Section titled “生成 Answers 模板”首先,生成一个包含所有必需字段的模板:
# Basic template (required fields only)gtc setup --dry-run --emit-answers answers.json ./my-bundle
# Full template (including optional fields)gtc setup --dry-run --emit-answers answers.json --advanced ./my-bundleAnswers 文件格式
Section titled “Answers 文件格式”{ "messaging-telegram": { "enabled": true, "public_base_url": "https://xxx.ngrok-free.app", "bot_token": "123456789:ABCdefGHIjklMNOpqrsTUVwxyz" }, "messaging-slack": { "enabled": true, "public_base_url": "https://xxx.ngrok-free.app", "api_base_url": "https://slack.com/api", "bot_token": "xoxb-xxx-xxx-xxx", "slack_app_id": "A07XXXXXX", "slack_configuration_token": "xoxe.xoxp-xxx" }, "messaging-teams": { "enabled": false }}messaging-telegram: enabled: true public_base_url: https://xxx.ngrok-free.app bot_token: "123456789:ABCdefGHIjklMNOpqrsTUVwxyz"
messaging-slack: enabled: true public_base_url: https://xxx.ngrok-free.app api_base_url: https://slack.com/api bot_token: xoxb-xxx-xxx-xxx slack_app_id: A07XXXXXX slack_configuration_token: xoxe.xoxp-xxx
messaging-teams: enabled: false应用 Answers
Section titled “应用 Answers”gtc setup --answers answers.json ./my-bundleProvider 专属配置
Section titled “Provider 专属配置”Telegram
Section titled “Telegram”{ "messaging-telegram": { "enabled": true, "public_base_url": "https://your-domain.com", "bot_token": "123456789:ABCdefGHIjklMNOpqrsTUVwxyz" }}如何获取凭据:
- 在 Telegram 上向 @BotFather 发送消息
- 发送
/newbot并按提示操作 - 复制 bot token
{ "messaging-slack": { "enabled": true, "public_base_url": "https://your-domain.com", "bot_token": "xoxb-xxx-xxx-xxx", "slack_app_id": "A07XXXXXX", "slack_configuration_token": "xoxe.xoxp-xxx" }}如何获取凭据:
- 前往 api.slack.com/apps
- 创建一个新应用或选择现有应用
- 在 OAuth & Permissions 中获取 Bot Token
- 在 Basic Information 中获取 App ID
- 在 App Manifest 中获取 Configuration Token
Microsoft Teams
Section titled “Microsoft Teams”{ "messaging-teams": { "enabled": true, "public_base_url": "https://your-domain.com", "app_id": "your-app-id", "app_password": "your-app-password", "tenant_id": "your-tenant-id" }}WhatsApp(通过 Meta)
Section titled “WhatsApp(通过 Meta)”{ "messaging-whatsapp": { "enabled": true, "public_base_url": "https://your-domain.com", "phone_number_id": "123456789", "access_token": "EAAxxxxx", "verify_token": "your-verify-token" }}公开 URL 配置
Section titled “公开 URL 配置”使用 ngrok
Section titled “使用 ngrok”# Start ngrok in separate terminalngrok http 8080
# Copy the HTTPS URL (e.g., https://abc123.ngrok-free.app)# Use this as public_base_url in answers使用 Cloudflared
Section titled “使用 Cloudflared”# Cloudflared generates URL automatically with gtc startgtc start ./my-bundle --cloudflared onSetup Flow 执行过程
Section titled “Setup Flow 执行过程”当你运行 gtc setup 时,它会:
-
加载 bundle 配置
读取
greentic.demo.yaml以查找 providers。 -
验证 answers
检查所有必需字段是否存在。
-
运行 setup flows
执行每个 provider 的
setup_flow(例如 webhook 注册)。 -
存储凭据
将凭据保存到已配置的 secrets store。
-
运行验证
执行
verify_flow以确认设置成功。
设置单个 Provider
Section titled “设置单个 Provider”gtc setup --provider messaging-telegram ./my-bundle跳过指定 Provider
Section titled “跳过指定 Provider”gtc setup --skip messaging-teams ./my-bundle重新运行 Setup
Section titled “重新运行 Setup”# Force re-setup (useful after URL changes)gtc start ./my-bundle --force-setupWebhook 注册失败
Section titled “Webhook 注册失败”Error: Failed to register webhook: 401 Unauthorized检查你的 bot token 是否正确且未过期。
缺少必填字段
Section titled “缺少必填字段”Error: Missing required field 'bot_token' for messaging-telegram确保 answers 文件中包含所有必填字段。
公开 URL 无法访问
Section titled “公开 URL 无法访问”Error: Webhook verification failed: Connection refused确保你的公开 URL 可从互联网访问。检查 ngrok/cloudflared 是否正在运行。
Error: Secret 'slack_bot_token' not found运行 gtc setup 来配置 provider,或检查你的 answers 文件。
- 在 CI/CD 中使用 answers 文件 - 避免在自动化流水线中使用交互式提示
- 妥善保护凭据 - 不要将包含真实 token 的 answers 文件提交到 git
- 使用环境变量 - 在 answers 中通过
$ENV_VAR引用 secrets - 使用 dry-run 测试 - 在实际更改前先预览 setup
- URL 变更后重新生成 - 当公开 URL 变化时重新运行 setup
- gtc start - 运行 runtime 服务器
- Telegram Setup - 详细的 Telegram 指南
- Slack Setup - 详细的 Slack 指南