Repository navigation
docs: add HTML page SDK API references #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
renjie-run
wants to merge
1
commit into
main
Choose a base branch
from
codex/add-html-page-links-users-actions-api-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,214 @@ | ||
| --- | ||
| description: seatable-html-page-sdk reference for sending notifications and emails, and running configured Python scripts from an HTML page. | ||
| --- | ||
|
|
||
| # Actions | ||
|
|
||
| Action operations on the `seatable-html-page-sdk`. They start asynchronous notification, email, or Python-script tasks. All methods are asynchronous — `await` them. The `sdk` instance below is created and initialized as shown in [Initialization](initialization.md). | ||
|
|
||
| !!! warning "Response format" | ||
|
|
||
| Action methods resolve to the underlying HTTP response. Read the payload from `.data`. Methods that start a task return its identifier in `.data.task_id`; retain this ID when the page needs to query task progress or results. | ||
|
|
||
| ## Notifications and email | ||
|
|
||
| !!! abstract "sendNotification" | ||
|
|
||
| Create a notification task associated with one row. | ||
|
|
||
| ```js | ||
| sdk.sendNotification({ tableName, rowId, emails, msg }); | ||
| ``` | ||
|
|
||
| __Parameters__ | ||
|
|
||
| `tableName` | ||
| : string — display name of the table containing the row | ||
|
|
||
| `rowId` | ||
| : string — `_id` of the row associated with the notification | ||
|
|
||
| `emails` | ||
| : array — non-empty list of recipient email addresses | ||
|
|
||
| `msg` | ||
| : string — non-empty notification text. It can contain row-value template placeholders such as `{Order number}`. | ||
|
|
||
| __Returns__ `.data` holds `{ task_id }` — use `task_id` with `getMessageStatus`. | ||
|
|
||
| __Example__ | ||
| ```js | ||
| const res = await sdk.sendNotification({ | ||
| tableName: "Orders", | ||
| rowId: "fcHIocncTsOygA3FjL-toQ", | ||
| emails: ["a7f34c91e2bd4d6b8a50f1c73e9d2a48@auth.local"], | ||
| msg: "Your order {Order number} has been shipped.", | ||
| }); | ||
| const taskId = res.data.task_id; | ||
| ``` | ||
|
|
||
| !!! abstract "sendEmail" | ||
|
|
||
| Create an email task associated with one row. | ||
|
|
||
| ```js | ||
| sdk.sendEmail({ | ||
| tableName, | ||
| rowId, | ||
| accountName, | ||
| sendTo, | ||
| copyTo, | ||
| replyTo, | ||
| subject, | ||
| message, | ||
| htmlMessage, | ||
| attachmentColumnNames, | ||
| }); | ||
| ``` | ||
|
|
||
| __Parameters__ | ||
|
|
||
| `tableName` | ||
| : string — display name of the table containing the row | ||
|
|
||
| `rowId` | ||
| : string — `_id` of the row associated with the email | ||
|
|
||
| `accountName` | ||
| : string — name of the configured email account | ||
|
|
||
| `sendTo` | ||
| : array — non-empty list of recipient email addresses or row-value templates | ||
|
|
||
| `copyTo` | ||
| : array — optional list of CC email addresses or row-value templates | ||
|
|
||
| `replyTo` | ||
| : string — optional Reply-To email address or row-value template | ||
|
|
||
| `subject` | ||
| : string — non-empty plain-text email subject | ||
|
|
||
| `message` | ||
| : string — plain-text body template | ||
|
|
||
| `htmlMessage` | ||
| : string — HTML body template | ||
|
|
||
| `attachmentColumnNames` | ||
| : array — optional list of FILE column display names; do not use column keys | ||
|
|
||
| `message` and `htmlMessage` must provide exactly one body: do not pass both, and do not omit both. Recipient values and the message body can use row-value template placeholders such as `{Customer email}` and `{Order number}`. | ||
|
|
||
| __Returns__ `.data` holds `{ task_id }` — use `task_id` with `getMessageStatus`. | ||
|
|
||
| __Example__ | ||
| ```js | ||
| const res = await sdk.sendEmail({ | ||
| tableName: "Orders", | ||
| rowId: "fcHIocncTsOygA3FjL-toQ", | ||
| accountName: "Operations SMTP", | ||
| sendTo: ["customer@example.com"], | ||
| copyTo: ["orders-audit@example.com"], | ||
| replyTo: "support@example.com", | ||
| subject: "Order shipment notification", | ||
| htmlMessage: "<p>Your order <strong>{Order number}</strong> has been shipped.</p>", | ||
| attachmentColumnNames: ["Invoice"], | ||
| }); | ||
| const taskId = res.data.task_id; | ||
| ``` | ||
|
|
||
| !!! abstract "getMessageStatus" | ||
|
|
||
| Get the status of a notification or email task returned by `sendNotification` or `sendEmail`. | ||
|
|
||
| ```js | ||
| sdk.getMessageStatus({ taskId }); | ||
| ``` | ||
|
|
||
| __Parameters__ | ||
|
|
||
| `taskId` | ||
| : string — task identifier returned in `response.data.task_id` | ||
|
|
||
| __Example__ | ||
| ```js | ||
| const res = await sdk.getMessageStatus({ taskId }); | ||
| if (res.data.is_finished) { | ||
| // Stop polling and update the UI. | ||
| } | ||
| ``` | ||
|
|
||
| Do not query the status until the task-starting method has returned its `task_id`. | ||
|
|
||
| ## Python scripts | ||
|
|
||
| !!! abstract "runScript" | ||
|
|
||
| Start a configured Python script. | ||
|
|
||
| ```js | ||
| sdk.runScript({ scriptName, tableName, rowId }); | ||
| ``` | ||
|
|
||
| __Parameters__ | ||
|
|
||
| `scriptName` | ||
| : string — displayed name of the configured script, not its internal ID or file name | ||
|
|
||
| `tableName` | ||
| : string — optional display name of the table that supplies the row context | ||
|
|
||
| `rowId` | ||
| : string — optional `_id` of the row that supplies the row context | ||
|
|
||
| Provide `tableName` and `rowId` together when the script needs a row context, or omit both when it does not. | ||
|
|
||
| __Returns__ `.data` holds `{ task_id }` — use `task_id` with `getScriptResult`. | ||
|
|
||
| __Example__ | ||
| ```js | ||
| const res = await sdk.runScript({ | ||
| scriptName: "Generate order report", | ||
| tableName: "Orders", | ||
| rowId: "fcHIocncTsOygA3FjL-toQ", | ||
| }); | ||
| const taskId = res.data.task_id; | ||
| ``` | ||
|
|
||
| !!! abstract "getScriptResult" | ||
|
|
||
| Get the result of a script started by `runScript`. | ||
|
|
||
| ```js | ||
| sdk.getScriptResult({ scriptName, taskId }); | ||
| ``` | ||
|
|
||
| __Parameters__ | ||
|
|
||
| `scriptName` | ||
| : string — the same displayed script name used to start the task | ||
|
|
||
| `taskId` | ||
| : string — task identifier returned in `runScript` response `.data.task_id` | ||
|
|
||
| __Returns__ `.data` holds `{ script }`. The `script` object includes `state`, `success`, `output`, `return_code`, `started_at`, and `finished_at`. | ||
|
|
||
| __Example__ | ||
| ```js | ||
| const res = await sdk.getScriptResult({ | ||
| scriptName: "Generate order report", | ||
| taskId, | ||
| }); | ||
| const scriptResult = res.data.script; | ||
|
|
||
| if (scriptResult.state === "finished") { | ||
| if (scriptResult.success) { | ||
| // The script completed successfully. | ||
| } else { | ||
| // Inspect scriptResult.return_code and scriptResult.output. | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Query the result only with the `taskId` returned by the corresponding `runScript` call. Treat `success: false` or a non-zero `return_code` as a failed execution, and render `output` as plain text rather than HTML. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, these methods will arrive with version 1.0 of the SDK, right?
Does it make sense to indicate this somewhere on the page?
We already have customers that have created HTML pages in the past. They won't be able to use these methods until they upgrade the SDK version.
This could be as simple as the notice here: https://developer.seatable.com/python/objects/context/#current_view (a field that is only available as of version 6.2)