Skip to content

Commit

Permalink
docs: fix getting started example and description
Browse files Browse the repository at this point in the history
  • Loading branch information
ahochsteger committed Oct 20, 2023
1 parent cd5ac6f commit df794ec
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 31 deletions.
41 changes: 20 additions & 21 deletions docs/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,34 @@ Follow these steps:
- See the [Gmail Processor Release Notes](https://github.com/ahochsteger/gmail-processor/releases) for their corresponding Google Apps Script library version.
- Or use this URL to verify the release version of a Google Apps Script Library: <https://script.google.com/macros/library/d/1Qvk0v7ggfW-TJ84dlYPlDzJG8y-Dif-j9kdA1aWv4wzxE_IOkeV2juLB/{libVersion}> (replace `{libVersion}` with the number from the drop-down in Google Apps Script).
5. Set the **identifier** to `GmailProcessorLib` (any name will do, but we will use this identifier as a reference in all [examples](examples/index.md) and documentation)
6. Replace the contents of the initially created file `Code.gs` with the code from the [Getting Started Example](examples/gettingStarted.mdx) and save the changes.
7. Perform an initial execution of the function `run` to grant all required permissions (see [Required API Permissions](#required-api-permissions) for more details):
6. Replace the contents of the initially created file `Code.gs` with the following code, take the config from the [Getting Started Example](examples/gettingStarted.mdx) and save the changes:
```javascript
var config = {
settings: {
// Decide the on the method to mark processed threads or messages:
markProcessedMethod: ...,
},
threads: [{}],
// Define your configuration JSON
}

function run() {
// NOTE: Switch to "safe-mode" after testing the config
GmailProcessorLib.run(config, "dry-run")
}
```
8. Perform an initial execution of the function `run` to grant all required permissions (see [Required API Permissions](#required-api-permissions) for more details):
1. Select your account you want to grant access for
2. When the message "Google did not verify the app" click on "Advanced" and "Go to ..." to proceed
3. Grant access to all listed apps by clicking "Allow"

Now you can start using the Gmail Processor Library in your script file (e.g. `Code.gs`) of your Google Apps Script project as follows:

```javascript
var config = {
settings: {
// Decide the mark processed method to be used:
markProcessedMethod: GmailProcessorLib.MarkProcessedMethod.MY_CHOSEN_METHOD,
},
threads: [{}],
// Define your configuration JSON
}

function run() {
// NOTE: Switch to "safe-mode" after testing the config
GmailProcessorLib.run(config, "dry-run")
}
```

Adjust the configuration (see section [Configuration Reference](reference/index.md)) to your needs. It's always recommended to test config changes using a _dry-run_ by passing `dry-run` as the 2nd parameter to the `run` function. That doesn't touch anything (neither in GMail nor GDrive) but produces a log that shows what would have been done. This way any change in your configuration or an upgrade to a newer version of the library can be tested without any risk of data-loss.
Adjust the configuration (see section [Configuration Reference](reference/index.md)) to your needs. It's always recommended to test config changes using the run mode `dry-run` (2nd parameter to the `run()` function). That doesn't touch anything (GMail, GDrive, Google Sheets) but produces a log that shows what would have been done. This way any change in your configuration or an upgrade to a newer version of the library can be tested without any risk of data-loss.

If you're satisfied with the results change the run mode from `dry-run` to `safe-mode` to actually do the processing and execute the `run` function again.
For automatic triggering you can create a [time-based trigger](https://developers.google.com/apps-script/guides/triggers/installable#manage_triggers_manually) that runs at certain intervals (e.g. once per day or every hour).

Should you run into any problems please create an issue and put the configuration as well as the log output there. Make sure to remove any sensitive information before doing so, since the issue contents will be publicly visible.

## Copy the Library Code (advanced)

To use a copy of the library code in your project simply replace steps 3-5 from above with the following steps:
Expand Down
13 changes: 7 additions & 6 deletions src/gas/examples/gettingStarted.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export const config = {
settings: {
// Decide on the method to be used to mark processed threads/messages:
// MARK_MESSAGE_READ: Mark each processed messages as read (can deal with multiple messages per thread but touches the read status)
markProcessedMethod:
GmailProcessorLib.MarkProcessedMethod.MARK_MESSAGE_READ,
// markProcessedMethod:
// GmailProcessorLib.MarkProcessedMethod.MARK_MESSAGE_READ,
// ADD_THREAD_LABEL: Add a label (specified by markProcessedLabel) to the processed thread (unable to deal with multiple messages per thread, but doesn't touch the read status)
// markProcessedMethod: GmailProcessorLib.MarkProcessedMethod.ADD_THREAD_LABEL,
// markProcessedLabel: "GmailProcessor/processed",
markProcessedMethod: GmailProcessorLib.MarkProcessedMethod.ADD_THREAD_LABEL,
markProcessedLabel: "GmailProcessor/processed",

// Add more settings if required ...
},
Expand All @@ -36,8 +36,9 @@ export const config = {
{
name: "thread.storePDF",
args: {
folder:
"folder/${message.date:format:yyyy-MM-dd}/${attachment.name}",
location:
"folder/${message.date:format:yyyy-MM-dd}/${thread.firstMessageSubject}.pdf",
conflictStrategy: "keep",
},
},
],
Expand Down
6 changes: 4 additions & 2 deletions src/gas/examples/gettingStarted.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"description": "This is a getting started example configuration.",
"settings": {
"markProcessedMethod": "mark-read"
"markProcessedMethod": "add-label",
"markProcessedLabel": "GmailProcessor/processed"
},
"global": {},
"threads": [
Expand All @@ -18,7 +19,8 @@
{
"name": "thread.storePDF",
"args": {
"folder": "folder/${message.date:format:yyyy-MM-dd}/${attachment.name}"
"location": "folder/${message.date:format:yyyy-MM-dd}/${thread.firstMessageSubject}.pdf",
"conflictStrategy": "keep"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/lib/config/SettingsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class SettingsConfig {
@Expose()
maxRuntime? = 280
/**
* The label to be added to processed GMail threads (only for markProcessedMode="label", deprecated - only for compatibility to v1)
* The label to be added to processed GMail threads (only for markProcessedMode="label").
*/
@Expose()
markProcessedLabel? = ""
Expand Down
2 changes: 1 addition & 1 deletion src/lib/config/config-schema-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@
},
"markProcessedLabel": {
"default": "",
"description": "The label to be added to processed GMail threads (only for markProcessedMode=\"label\", deprecated - only for compatibility to v1)",
"description": "The label to be added to processed GMail threads (only for markProcessedMode=\"label\".",
"title": "markProcessedLabel",
"type": "string"
},
Expand Down

0 comments on commit df794ec

Please sign in to comment.