{"id":21387537,"url":"https://github.com/nju33/tirashi-observer-bot","last_synced_at":"2025-03-16T12:29:08.314Z","repository":{"id":43532766,"uuid":"503982908","full_name":"nju33/tirashi-observer-bot","owner":"nju33","description":"A Line bot by GAS: this allows you to observe words that you want to from given flyers.","archived":false,"fork":false,"pushed_at":"2023-03-06T09:29:50.000Z","size":1103,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-11-22T12:13:25.988Z","etag":null,"topics":["gitpod-workspace"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nju33.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-16T02:16:28.000Z","updated_at":"2022-07-02T16:16:19.000Z","dependencies_parsed_at":"2022-09-01T14:13:32.903Z","dependency_job_id":null,"html_url":"https://github.com/nju33/tirashi-observer-bot","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"nju33/gitpod-workspace","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nju33%2Ftirashi-observer-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nju33%2Ftirashi-observer-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nju33%2Ftirashi-observer-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nju33%2Ftirashi-observer-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nju33","download_url":"https://codeload.github.com/nju33/tirashi-observer-bot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235204562,"owners_count":18952331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gitpod-workspace"],"created_at":"2024-11-22T12:13:31.282Z","updated_at":"2025-01-23T00:14:39.224Z","avatar_url":"https://github.com/nju33.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tirashi Observer Bot\n\n[![Test](https://github.com/nju33/tirashi-observer-bot/actions/workflows/test.yml/badge.svg)](https://github.com/nju33/tirashi-observer-bot/actions/workflows/test.yml)\n\nTirashi Observer Bot is a Line bot by GAS: this allows you to observe words that you want to from given flyers.\n\n## Youtube Video for introducing\n\n[![Tirashi Observer Bot の紹介](http://img.youtube.com/vi/RuEmiDFWPGQ/0.jpg)](http://www.youtube.com/watch?v=RuEmiDFWPGQ)\n\n## Dependencies\n\n1. [cron-job.org](https://console.cron-job.org/)\n2. [Line](https://developers.line.biz/ja/)\n3. [Google Apps Script](https://www.google.com/script/start/)\n\n```mermaid\nsequenceDiagram\n\nparticipant Cron as cron-job.org\nparticipant GAS as Google Apps Script\nparticipant Line\nactor you\nparticipant S as Supermarket\n\nloop Everyday around 8 a.m.\n    Cron -) GAS: Fire `doGet`\n\n    opt Flyers contains some registerd words\n        GAS -) Line: Send a message about\u003cbr /\u003ewhether the flyer contains words that you want\n        Line -) you: Inform\n        you -) S: Shipping\n    end\nend\n```\n\n## Usecases\n\n1. You can register a word to want to observe.\n2. You can list registered words.\n3. You can toggle the state of a registered word.\n4. You can delete a registered word.\n5. You can receive a message when encountering registered words on tirashis.\n\n## Directory Structure\n\nThis project is using `yarn@berry` as a package manager; also, the workspace feature is being used.\n\n```bash\n. # Workspace root package\n├── appsscript.json\n├── package.json # The config for the workspace root package\n├── projects\n│   └── tirashi-observer-bot # A workspace\n│       ├── package.json # The config for the workspace package\n│       ├── .clasp.json # Contains `rootDir` as `../..`\n│       ├── .claspignore\n│       └── src # Place the main code to do `doGet` etc\n│           └── script.ts\n├── _properties.ts # To initialize properties\n└── README.md\n```\n\nThis project doesn't actually have such as `.clasp.json`. That's because It doesn't exist that way to hide secret values.\n\nAs a solution to this, actually in my local, mounting `/projects/tirashi-observer-bot/` with my cloud storage. Then all of the files below here are synced with one from the cloud storage. (In short, such as `.clasp.json` exists on the cloud storage)\n\n## Preparing For Workspace\n\n```bash\nyarn\n```\n\n## Preparing For GAS\n\n1. Install GAS\n    ```bash\n    npm install --location=global @google/clasp\n    ```\n2. Setup GAS to be able to use `clasp run`.  \n   Please refer to [here](https://github.com/google/clasp/blob/master/docs/run.md#run)\n3. Create a `.clasp.json` on the `projects/tirashi-observer-bot/` directory, and edit it to be like this:\n    ```json\n    {\n        \"scriptId\": \"\u003cyour-script-id\u003e\",\n        \"projectId\": \"\u003cyour-project-id-on-gcp\u003e\",\n        \"rootDir\": \"../..\",\n        \"fileExtension\": \"ts\",\n        \"filePushOrder\": [\n            \"../../projects/tirashi-observer-bot/src/constants.ts\",\n            \"../../projects/tirashi-observer-bot/src/error.ts\",\n            \"../../_user-function.ts\",\n            \"../../_properties.ts\",\n            \"../../_sheets.ts\",\n            \"../../appsscript.json\",\n            \"../../projects/tirashi-observer-bot/src/domains/document.ts\",\n            \"../../projects/tirashi-observer-bot/src/domains/drive.ts\",\n            \"../../projects/tirashi-observer-bot/src/domains/fetch.ts\",\n            \"../../projects/tirashi-observer-bot/src/domains/folder-id-where-flyer-downloads.ts\",\n            \"../../projects/tirashi-observer-bot/src/domains/chat.ts\",\n            \"../../projects/tirashi-observer-bot/src/domains/token.ts\",\n            \"../../projects/tirashi-observer-bot/src/domains/tirashi-url.ts\",\n            \"../../projects/tirashi-observer-bot/src/domains/line.ts\",\n            \"../../projects/tirashi-observer-bot/src/domains/regexp.ts\",\n            \"../../projects/tirashi-observer-bot/src/domains/list-line-message.ts\",\n            \"../../projects/tirashi-observer-bot/src/domains/script-properties.ts\",\n            \"../../projects/tirashi-observer-bot/src/domains/to-sheet-value.ts\",\n            \"../../projects/tirashi-observer-bot/src/domains/words-each-users.ts\",\n            \"../../projects/tirashi-observer-bot/src/domains/user.ts\",\n            \"../../projects/tirashi-observer-bot/src/domains/word.ts\",\n            \"../../projects/tirashi-observer-bot/src/domains/repository.ts\",\n            \"../../projects/tirashi-observer-bot/src/line.ts\",\n            \"../../projects/tirashi-observer-bot/src/services/line-fetch.ts\",\n            \"../../projects/tirashi-observer-bot/src/services/line-message.ts\",\n            \"../../projects/tirashi-observer-bot/src/services/chat-action-reply-message.ts\",\n            \"../../projects/tirashi-observer-bot/src/services/words-matched-message.ts\",\n            \"../../projects/tirashi-observer-bot/src/presentation/line-message.ts\",\n            \"../../projects/tirashi-observer-bot/src/presentation/list-line-message.ts\",\n            \"../../projects/tirashi-observer-bot/src/presentation/chat-action-reply-message.ts\",\n            \"../../projects/tirashi-observer-bot/src/presentation/words-matched-message.ts\",\n            \"../../projects/tirashi-observer-bot/src/infrastructure/document.ts\",\n            \"../../projects/tirashi-observer-bot/src/infrastructure/drive.ts\",\n            \"../../projects/tirashi-observer-bot/src/infrastructure/fetch.ts\",\n            \"../../projects/tirashi-observer-bot/src/infrastructure/line-fetch.ts\",\n            \"../../projects/tirashi-observer-bot/src/infrastructure/script-properties.ts\",\n            \"../../projects/tirashi-observer-bot/src/infrastructure/user-sheet.ts\",\n            \"../../projects/tirashi-observer-bot/src/infrastructure/word-sheet.ts\",\n            \"../../projects/tirashi-observer-bot/src/usecases/chat.ts\",\n            \"../../projects/tirashi-observer-bot/src/usecases/delete-registered-word.ts\",\n            \"../../projects/tirashi-observer-bot/src/usecases/activate-registered-word.ts\",\n            \"../../projects/tirashi-observer-bot/src/usecases/examine-flyers-by-words.ts\",\n            \"../../projects/tirashi-observer-bot/src/usecases/inactivate-registered-word.ts\",\n            \"../../projects/tirashi-observer-bot/src/usecases/list-registered-words.ts\",\n            \"../../projects/tirashi-observer-bot/src/usecases/register-word.ts\"\n        ]\n    }\n    ```\n4. Also, register the number of the same project from the settings page of the script editor. (You can open the script editor by `clasp open`)  \n   ![](https://cloud.nju33.com/eXx2280ZyFwQSsOwwTXf+)\n5. Setup the script properties.\n    1. Set `TIRASHI_URL` and `LINE_TOKEN`. For that like propose, like the below command is executed.\n        ```bash\n        yarn tob:$ _initScriptProperties \\\n          --params '{\"TIRASHI_URL\": \"url1,url2,...\", \"LINE_TOKEN\": \"...\"}'\n          # ^ If you want to search words from multiple flyers,\n          #   you can specify a value separated by `,`.\n        ```\n    2. If you want to change where flyers are downloaded tempolary (for any destructive issues), you can similarly set the `TEMPORARY_DIRECTORY_TO_DOWNLOAD_FLYER`.\n\n### Note about TIRASHI_URL\n\n\u003c!-- It cannot be used as the `TIRASHI_URL` that a URL contains params. For example, as `https://example.com?key=aqwsedrftgyhujikolp`. When using like URL, Line throws an error `invalid uri scheme` at least.\nAnd maybe, There are further conditions to occur errors.\n\nIf feeling that the URL you want to use is complex, I recommend using the redirect feature of Firebase’s hosting. The URL is cleaned by using this. --\u003e\n\nWhen Line gets a flyer image, its content is returned from the cache after the second time; therefore, changing the URL every time is needed.\n\nTo take the measure of this, Firebase’s hosting feature is used in the like below:\n\n1. Open `firebase.json`\n2. Add `hosting.redirects` in the below.\n    ```json\n    {\n        \"hosting\": {\n            \"...\": \"...\",\n            \"redirects\": [\n                {\n                    \"source\": \"/cleaned-image-url/**\",\n                    \"destination\": \"https://example.com?key=aqwsedrftgyhujikolp\",\n                    \"type\": 301\n                }\n            ]\n        }\n    }\n    ```\n3. `firebase deploy`\n4. Done. Now, you can access to `https://example.com?key=aqwsedrftgyhujikolp` via `\u003cyour-hosting-url\u003e/cleaned-image-url/123456789`\n\n#### Note\n\nYou don't include the last directory (`123456789` as mentioned above) in the TIRASHI_URL.\n\n-   👍 `\u003cyour-hosting-url\u003e/cleaned-image-url`\n-   👎 `\u003cyour-hosting-url\u003e/cleaned-image-url/123456789`\n\n## Code notes\n\n### About Export and Import\n\nThis project has a lot of code like the one below.\n\n```ts\nconst A: typeof _A = typeof _A === 'undefined' ? exports.A : _A\n// As a side note, the above is registered as a snippet to use typing `constimported` in a `.ts` file.\n```\n\nMainly, that reason is for coexistence in standard code on GAS and tests.\n\nFirst about `typeof _A === 'undefined'`. This comfirms to `_A` is defined. That's because pushed codes by clasp are to comment out all of `import` lines. In short, the `_A` imported is always undefined on GAS, and GAS throws an error when we immediately try to access it. So, comfirming defined it before accesing.\n\nOn the other hand, all of `import` lines are fine when running tests (by jest). In short, the `_A` imported is properly defined and able to use it.\n\nNext about `exports.A`. All of `export \u003cname\u003e ...` lines of uploaded codes, which is writing by Typescript, by clasp transpile into `exports.\u003cname\u003e = …` or `\u003cname\u003e …`. In each files, redefining of the `\u003cname\u003e` is needed; so, this project is using `exports.\u003cname\u003e = …`.\n\nIf GAS throws an error around here, the matter is a typo of the code or incorrect orders of pushing files. In the letter case, we could fix this to set correct orders to the [\"filePushOrder\" of the clasp config](https://github.com/google/clasp#project-settings-file-claspjson).\n\n## Hosting\n\nThis project makes very small use of the hosting feature of Firebase. It is for using icons in a Line message.\n\nIts preparation is the following.\n\n```bash\n# Install Firebase\nnpm install --location=global firebase-tools\n\n# Login to Firebase, and set FIREBASE_TOKEN for using firebase-cli features.\nfirebase login:cli\n# ... prints the token\nexport FIREBASE_TOKEN=\u003cPaste the above token\u003e\n\n# Deploy\nfirebase deploy\n```\n\n`/public/` directory is the root of the hosting.\n\n### Icons\n\nIcons are placed on the `/public/tinified/`; also, all of the icons (png) were minified by https://tinypng.com/.\n\n## Run Scripts\n\n### tob:\n\nRun a script that is defined on the `tirashi-observer-bot` workspace.\n\n#### push\n\nPush local codes to the remote project.\n\n#### deployments\n\nCan list deployments of the remote project.\n\n#### deploy\n\nCreate a new deployment by the state at the time.\n\n#### update\n\nUpdate the newest deployment by the state at the time.\n\n### tob:$\n\nRun codes on the remote project from local.\n\n## Test\n\nThis project depends on [Jest](https://jestjs.io/)](https://jestjs.io/) testing framework.\n\n### Setup\n\n1. `mv .jest/setup-process-env.js.sample .jest/setup-process-env.js`\n2. Open it, then put `LINE_TOKEN`\n3. Run `yarn build`. If you are a VSCode user, It’s also ok that run VSCode's build task(by `cmd+shift+b`)\n\nSome test cases have `.skip`. This prevents sending an actual request to another.\n\nIf testing them, remove it first before you run `yarn test`; also, you reattach `.skip` to one when finished before `git push`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnju33%2Ftirashi-observer-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnju33%2Ftirashi-observer-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnju33%2Ftirashi-observer-bot/lists"}