AnyBot/docs/feature-map/deliver.md

42 lines
6.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 交出結果:傳檔、打開、發佈網站
Bot 做好的東西用三種方式交給使用者:放進聊天變成檔案卡片、直接在使用者的螢幕上打開,或發佈成公開網站。傳到帳號裡另一台裝置是 `send_to_device`,見 [computers](computers.md)。
## 子功能
- `deliver-send` 傳檔:`send_file` 把檔案放進聊天變成檔案卡片,點一下預覽、可以下載。
- `deliver-open` 打開給使用者看:`open_for_person` 在使用者的螢幕上打開檔案或網址。
- `deliver-publish` 發佈網站:`publish_site` 把一個 .html 檔或有 index.html 的資料夾發佈成公開網站,回傳網址,同一個名字再發佈就取代。
## 使用者怎麼到
- `send_file` 的檔案卡片在回覆裡,點一下預覽(「下載檔案」「用其他 App 打開」);右側面板「資料庫」也列出這個對話裡的檔案。
- `publish_site` 要先在 設定 › 一般 ›「手機與帳號」登入帳號才有([account](account.md))。
- 手機:聊天裡的檔案卡片,點了在 App 裡預覽、右上角存到手機;聊天右上「⋯」›「對話詳細資訊」›「資料庫」([phone](phone.md))。
## 怎麼操作(verify-anybot)
- Bot:交結果用 `send_file`,不要只說檔案在哪;要使用者馬上看到用 `open_for_person`;要公開網址用 `publish_site`(path,name 只用英文字母、數字和 -)。`open_for_person`、`publish_site` 屬於「檔案與指令」能力,`send_file` 每個 Bot 都有。
前提:
- 基本前提和「手機已登入」(README),開著 Bot 1 的聊天:`$CTL phone click '.row[data-bot="1"]'`。
- scratch 的大腦是 `--serve`(AnyBot 在伺服器上)、沒有登入帳號;Bot 的檔案在它自己的電腦(沙盒資料夾)。
- **傳檔、預覽**(covers `deliver-send`):請 Bot 寫 report.md 傳給你,點卡片看,再看資料庫。指令:`$CTL phone send '寫報告 [[call edit_file {"path":"report.md","old_text":"","new_text":"# 本週報告\n\n一切順利。\n"}]]' && $CTL phone wait-text 已建立 --in '#msgs' && $CTL phone send '傳給我 [[call send_file {"path":"report.md"}]]' && $CTL phone wait 'a.filec[data-name="report.md"]' && $CTL phone shot deliver-card && $CTL phone click 'a.filec[data-name="report.md"]' && $CTL phone wait-text 一切順利 --in '#filebody' && $CTL phone shot deliver-preview && $CTL phone click '[data-back]' && $CTL phone click '#b-chatmore' && $CTL phone click '#sheet-in .opt' --text 對話詳細資訊 && $CTL phone click '[data-tab="library"]' && $CTL phone wait-text 'Bot 傳的' --in '#details' && $CTL api GET /api/bots/1 --jq '[.messages[].attachments[]? | {name, kind, bytes}]'`。看到:回覆下有「report.md · Markdown · 1 KB · 點一下開啟」的卡片;點開是排好的「本週報告/一切順利。」;資料庫的「檔案」有 report.md(Bot 傳的);API 的附件是 report.md、Markdown、32 bytes。
- **機密檔案不傳**(covers `deliver-send`):請 Bot 把 .env 傳給你。指令:`$CTL phone click '[data-back]' && $CTL phone send '寫 [[call edit_file {"path":".env","old_text":"","new_text":"TOKEN=abc"}]]' && $CTL phone wait '.step.done' --text .env && $CTL phone send '傳 [[call send_file {"path":".env"}]]' && $CTL phone wait '.step.denied' --text 傳檔案給你 && $CTL api GET /api/bots/1 --jq '[.messages[].tools[]? | select(.name == "send_file") | .status]'`。看到:Bot 自己的電腦上寫 .env 照樣成功,但傳檔那一步被擋:「被安全規則擋下:「…/.env」是私密或系統檔案,Bot 不能讀取。」;兩個 send_file 是 done、denied,聊天沒有第二張卡片。
- **伺服器上打不開**(covers `deliver-open`):請 Bot 打開 report.md,再打開一個網址。指令:`$CTL phone send '打開 [[call open_for_person {"path":"report.md"}]]' && $CTL phone wait-text '改用 send_file' --in '#msgs' && $CTL phone send '打開網址 [[call open_for_person {"path":"https://example.com/"}]]' && $CTL phone wait-text '不知道使用者現在在用哪台電腦' --in '#msgs' && $CTL api GET /api/bots/1 --jq '[.messages[].tools[]? | select(.name == "open_for_person") | .status]'`。看到:「AnyBot 在伺服器上,檔案沒辦法直接在使用者的螢幕打開。改用 send_file…」;網址是「不知道使用者現在在用哪台電腦,沒辦法打開給他看。把網址直接寫在回覆裡。」;兩步都是 failed。
- **沒登入就沒有發佈**(covers `deliver-publish`):指令:`$CTL phone send '發佈 [[call publish_site {"path":"report.md","name":"report"}]]' && $CTL phone wait-text '這一輪沒有 publish_site 這個工具' --in '#msgs' && $CTL model 'select(.want) | .want'`。看到:Bot 拿到的工具裡沒有 `publish_site`(假模型列出它有的);模型那層記下想要的是 publish_site。
- **打開在螢幕上、真的發佈**(covers `deliver-open`、`deliver-publish`):指令:走不到——打開要「這台電腦」或使用者正在用的帳號裡的電腦,發佈要帳號伺服器(`relay/`)。看到:最接近的真路是上面兩步的拒絕,和自動測試裡在這台電腦上傳檔、打開(工作資料夾外先問、程式或指令檔不打開、機密檔案不傳)。
- **桌面的預覽**(covers `deliver-send`):指令:要開視窗——`$CTL stop && ABV_ALLOW_WINDOW=1 $CTL desktop-shot deliver-preview ANYBOT_SHOT_VIEW=fileview`。看到:示範的試算表在預覽裡打開,上面有「下載檔案」「用其他 App 打開」。
- 自動測試:`cargo test tools::`、`cargo test preview::`、`cargo test app::files_ui::`、`cargo test agent::`(`a_file_leaves_a_computer_only_past_the_questions_of_reading_it`)。
## 陷阱
- 機密檔案不能傳、打開或發佈([files](files.md))。
- `open_for_person` 不打開程式或指令檔(打開就會執行),改用 `send_file`;AnyBot 在伺服器上時,網址會在使用者正在用的那台電腦打開(不知道是哪台就打不開),檔案打不開,也改用 `send_file`。
- SSH 電腦上的檔案不能直接 `send_file`、`open_for_person` 或 `publish_site`;帳號裡其他電腦的檔案可以 `send_file`(最多 20 MB),但不能打開或發佈。先複製到 Bot 自己的電腦。
- `publish_site`:任何知道網址的人都看得到。每個網站名字第一次會問(工作資料夾外的每次都問);最多 500 個檔案、25 MB;點開頭的檔案、node_modules、機密檔案、指到資料夾外的連結會略過;一定要有 index.html。
- 「在這台電腦上執行」設成永不允許(或被管理員鎖住)時,這台的檔案也不能傳出去、打開或發佈。
- (驗證)scratch 只有 Bot 自己的電腦:私密檔案的規則在那裡只擋傳出去(寫 .env 照樣成功),不能拿來證明「不能讀」。