Mình vừa thử và thấy đây là một trong những ứng dụng GPT Actions dễ hiểu nhất, nhưng lại cực kỳ hữu ích nếu mng làm việc nhiều với Google Workspace hoặc cần tự động hóa báo cáo, SOP, proposal, nội dung nội bộ.
Cách hoạt động tổng quan
Chúng ta sẽ dùng Google Apps Script để tạo một API đơn giản, cho phép ChatGPT:
-
Đọc nội dung trong Google Docs (ở dạng JSON)
-
Ghi lại nội dung mới vào file Docs đó
Sau đó, tạo Custom GPT có thể gọi API này thông qua GPT Actions.
Kết quả: ChatGPT có thể đọc – chỉnh sửa – cập nhật file Google Docs của bạn như một cộng tác viên thật sự.
Kết quả: ChatGPT có thể đọc – chỉnh sửa – cập nhật file Google Docs của bạn như một cộng tác viên thật sự.
Các bước thực hiện
Bước 1 – Chuẩn bị file Google Docs
-
Mở file Google Docs mà bạn muốn ChatGPT thao tác.
-
Nhấn nút Chia sẻ → Bất kỳ ai có liên kết → Người xem.
-
Sao chép lại ID trong đường dẫn (nằm giữa
/d/và/edit).
Ví dụ:
https://docs. google. com/document /d/**ID_CUA_BAN**/edit
Bước 2 – Viết đoạn mã Apps Script
-
Trên Google Docs, vào menu: Tiện ích → Apps Script.
-
Xóa hết nội dung mặc định, dán đoạn mã dưới đây:
function doGet(e) {const docId = e.parameter.id || '1UesvO7Fe2GdVnAZ9JKf4TbXcPKKcS_zzpM3yFXPGANE'; // fallback to default Doc IDtry {const doc = DocumentApp.openById(docId);const body = doc.getBody().getText();return ContentService.createTextOutput(JSON.stringify({ status: 'success', content: body })).setMimeType(ContentService.MimeType.JSON);} catch (error) {return ContentService.createTextOutput(JSON.stringify({ status: 'error', message: error.message })).setMimeType(ContentService.MimeType.JSON);}
}
function doPost(e) {try {const data = JSON.parse(e.postData.contents);const docId = data.id || '1UesvO7Fe2GdVnAZ9JKf4TbXcPKKcS_zzpM3yFXPGANE'; // fallback to default Doc IDconst content = data.content;if (!content) throw new Error("Missing 'content' in request body.");const doc = DocumentApp.openById(docId);const body = doc.getBody();body.setText(content); // Replace all existing content with new textreturn ContentService.createTextOutput(JSON.stringify({ status: 'success', message: 'Content written successfully.' })).setMimeType(ContentService.MimeType.JSON);} catch (error) {return ContentService.createTextOutput(JSON.stringify({ status: 'error', message: error.message })).setMimeType(ContentService.MimeType.JSON);}
}
Bước 3 – Triển khai Script thành Web API
-
Nhấn Triển khai → Tùy chọn triển khai mới
-
Chọn Ứng dụng web (Web App)
-
Mục Ai có thể truy cập: chọn Bất kỳ ai
-
Nhấn Triển khai → Sao chép URL Web App (ví dụ:
https://script .google . com/macros/s/xxxx/exec)
Bước 4 – Kiểm tra API
-
Dán URL vào trình duyệt.
-
Nếu thấy nội dung Docs trả về ở dạng JSON, bạn đã kết nối thành công.
Bước 5 – Tạo Custom GPT trên ChatGPT
-
Vào Explore GPTs → Create → Actions → Create new action.
-
Dán đoạn OpenAPI schema dưới đây và thay URL Web App của bạn vào:
openapi: 3.1.0info:title: Google Docs Content APIdescription: |A simple API to retrieve or update the plain text content of a Google Doc using a Google Apps Script Web App.
version: 1.1.0servers:- url: https://script. google. com/macros/s/URL_WEB_APP_CUA_BAN/execpaths:/exec:get:operationId: getGoogleDocContentsummary: Retrieve the plain text content of a Google Doc.parameters:- name: idin: queryrequired: falseschema:type: stringresponses:"200":description: JSON response with the document content.post:operationId: writeGoogleDocContentsummary: Write plain text content to a Google Doc.requestBody:required: truecontent:application/json:schema:type: objectproperties:id:type: stringcontent:type: stringrequired:- contentresponses:"200":description: JSON response indicating success or error.Bước 6 – Hoàn tất và thử nghiệm
-
Đặt tên GPT, ví dụ: GoogleDocs Assistant
-
Thêm hướng dẫn: “Hãy đọc và tóm tắt nội dung trong Google Docs.”
-
Thử hỏi:
“Tài liệu Google Docs này nói gì?”
“Hãy ghi nội dung này vào tài liệu Google Docs giúp tôi.”
“Hãy ghi nội dung này vào tài liệu Google Docs giúp tôi.”
Nếu cấu hình đúng, ChatGPT sẽ đọc và ghi tài liệu theo thời gian thực.
Kết quả sau khi thiết lập


Xem thêm:

















