Skip to main content

工具#

每个工具都接收 project_dir,即 tgcloud 项目的绝对路径(create_project 改为接收 parent_dir 和 name)。

生命周期 #

工具CLI说明
create_projectnpm create @tgcloud/bot新建项目(parent_dir、name)
init_projecttgcloud init在现有目录中生成脚手架,能识别 Mini App
login_bottgcloud login用 CLI access token(app<id>:<secret>)绑定;令牌经 stdin,输出中掩码
add_moduletgcloud add新模块:handlers/<type>、endpoints/<name>、lib/<path>
upgradetgcloud upgrade把 0.2.0 之前的布局移入 tgcloud/。默认 dry_run: true;真正执行需要 confirm: true

同步 #

工具CLI说明
statustgcloud status本地相对快照的变化(离线),含静态文件差异和 webhook 是否同步
difftgcloud diff逐行 diff(离线)
pushtgcloud push原子部署。不构建前端,不迁移数据库。force: true 需要 confirm: true
deploynpm run build + tgcloud push若 package.json 有 build 脚本则先构建再 push。skip_build: true 只 push
pulltgcloud pull云端 → 快照和工作文件。不写入 Mini App 构建目录
fetchtgcloud fetch云端 → 只更新快照
resettgcloud reset丢弃本地模块修改;需要 confirm: true

数据 #

工具CLI说明
run_handlertgcloud run不部署即可运行 handler 或 endpoint。args 与 ctx 为 JSON5。args 是第一个参数(载荷:handler 为 Message,endpoint 为输入);ctx 是第二个(handler 的 ctx.update 是原始 Update,含 update_id;endpoint 为 initData)
migratetgcloud migrate默认 dry_run: true 只预览。应用时需要 dry_run: false 和 confirm: true。apply: "safe" 即 --safe;应用时默认 apply: "yes" 即 --yes。local: true 即 --local

Webhook #

工具CLI说明
webhook_statustgcloud webhookURL、allowed_updates、积压、投递错误、是否与 handlers 同步
webhook_synctgcloud webhook sync重新指向平台。drop_pending: true 需要 confirm: true

新增或删除 handler 后,webhook 可能不同步。push 不保证刷新。这种部署之后调用 webhook_sync。

流程#

  • 机器人没反应:webhook_status → status / diff → push → webhook_sync
  • 已部署日志:没有下载命令;先看 webhook_status 的最后投递错误,再用 run_handler 复现(它的 console.* 是本地输出,不是已部署机器人的)
  • push 时修订冲突:fetch → diff → push(或带 confirm 的 force)
  • 改 schema:编辑 schema.js → push → migrate(dry-run)→ 带 confirm 的 migrate。没有删除时用 apply: "safe"
  • Mini App 前端:用 deploy,不要只 push