From c300a37f9d03fb94014e3b7b3f7b3aad74d3f3ae Mon Sep 17 00:00:00 2001 From: cori schlegel <46317+cori@users.noreply.github.com> Date: Wed, 28 Dec 2022 14:57:14 -0600 Subject: [PATCH 1/9] Prep package.json for running on Glitch --- package.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1569716..06e16f6 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { "name": "telegroam", - "version": "1.0.0", + "version": "1.0.1", "description": "Send messages and photos to your own Telegram bot and have them appear in the Daily Notes page of your Roam graph.", "main": "proxy.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node proxy.js" }, "repository": { "type": "git", @@ -18,5 +19,8 @@ "homepage": "https://github.com/mbrock/telegroam#readme", "dependencies": { "cors-anywhere": "^0.4.4" + }, + "engines": { + "node": "14.x" } } From 25657fd25c414bd182946e4b1ae8eeec8b9aa34f Mon Sep 17 00:00:00 2001 From: cori <46317+cori@users.noreply.github.com> Date: Thu, 29 Dec 2022 06:00:55 +0000 Subject: [PATCH 2/9] delete heroku files --- .indium.json | 8 -------- Procfile | 1 - app.json | 5 ----- 3 files changed, 14 deletions(-) delete mode 100644 .indium.json delete mode 100644 Procfile delete mode 100644 app.json diff --git a/.indium.json b/.indium.json deleted file mode 100644 index c74680f..0000000 --- a/.indium.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "configurations": [ - { - "name": "Telegroam", - "type": "chrome" - } - ] -} diff --git a/Procfile b/Procfile deleted file mode 100644 index 56900e4..0000000 --- a/Procfile +++ /dev/null @@ -1 +0,0 @@ -web: node proxy.js diff --git a/app.json b/app.json deleted file mode 100644 index b143f3c..0000000 --- a/app.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Telegroam Proxy", - "description": "A proxy for making CORS requests to Telegram's bot API", - "repository": "https://github.com/mbrock/telegroam" -} From 29b2758e10ceaba3b6583167dc1d85473b928931 Mon Sep 17 00:00:00 2001 From: cori <46317+cori@users.noreply.github.com> Date: Thu, 29 Dec 2022 06:06:41 +0000 Subject: [PATCH 3/9] update telegroam.js from https://github.com/mbrock/telegroam/pull/30 with correct binary-semaphore API --- telegroam.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/telegroam.js b/telegroam.js index 2f877f2..8121d84 100644 --- a/telegroam.js +++ b/telegroam.js @@ -242,10 +242,10 @@ let url = urlWithParams( "https://www.openstreetmap.org/export/embed.html", { - layer: "mapnik", - bbox, - marker - }) + layer: "mapnik", + bbox, + marker + }) return { embed: `:hiccup[:iframe { @@ -548,14 +548,14 @@ roamAlphaAPI.util.generateUID() let lockPath = - `https://binary-semaphore.herokuapp.com/lock/${lockId}/${nonce}` + `https://binary-semaphore.glitch.me/lock/${lockId}/${nonce}` - let acquirePath = `${lockPath}/acquire` - let releasePath = `${lockPath}/release` + let acquirePath = `${lockPath}` + let releasePath = `${lockPath}` - for (;;) { + for (; ;) { let result = - await fetch(acquirePath, { method: "POST" }) + await fetch(acquirePath, { method: "PUT" }) if (result.status === lockStatus.ok) { currentLockPath = lockPath @@ -566,7 +566,7 @@ console.log("telegroam: releasing lock") currentLockPath = null try { - await fetch(releasePath, { method: "POST" }) + await fetch(releasePath, { method: "DELETE" }) } catch (e) { console.error(e) throw e @@ -581,7 +581,7 @@ } async function updateFromTelegramContinuously() { - for (;;) { + for (; ;) { try { let result = await runWithMutualExclusionLock({ waitSeconds: 30, From 8d6ef18d905c205386cf03456047b4c6d39cc348 Mon Sep 17 00:00:00 2001 From: cori <46317+cori@users.noreply.github.com> Date: Thu, 29 Dec 2022 06:24:53 +0000 Subject: [PATCH 4/9] Readme and comment updates for Glitch --- README.md | 19 +++++++------------ telegroam.js | 1 + 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 00b5731..46a63b9 100644 --- a/README.md +++ b/README.md @@ -4,21 +4,16 @@ Send messages and photos to your own Telegram bot and have them appear in the Daily Notes page of your Roam graph. You don't need to run any software or servers other than this -JavaScript plugin for your Roam graph. +JavaScript plugin for your Roam graph and, your own copy of the proxy implemented here, which you can Remix on Glitch. -## ⚠️ Warning! +## Prerequisites -If you use the default proxy URL as in the instructions below, your -media files will get passed through a trusted middleman. +You'll need a running instance of [binary-semaphore](https://github.com/cori/binary-semaphore) to point your `roam/js` script to. If you use the address in the `telegroam.js` file you'll be sending your mutex calls through my Glitch instance of that project, with no guarantees for continued maintenance or uptime, but the linked-to repo can help you get set up with your own coy on Glitch. -You can run your own proxy easily using Heroku's free tier. This is -how I run my proxy. - -Click the button below and Heroku will guide you through the whole -thing with zero configuration or coding. You will end up with your +You'll also want your own instance of the proxy implemented in _this_ project. Click the button below and you will get a Gllitch Remix of the proxy. You will end up with your very own proxy URL. -[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) +[![Remix on Glitch](https://cdn.glitch.com/2703baf2-b643-4da7-ab91-7ee2a2d00b5b%2Fremix-button-v2.svg)](https://glitch.com/edit/#!/remix/telegroam) ### Why is a proxy necessary? @@ -43,10 +38,10 @@ I will make this more convenient later. 4. Paste these nodes somewhere on the [[Telegram Bot]] page: - - Inbox Name:: [[Inbox]] + - Inbox Name:: [[Inbox]] _or whatever page you want these to appear under_ - API Key:: insert key you get from Telegram's bot system - {{[[TODO]]}} update the Telegram API key above - - Trusted Media Proxy:: https://telegram-cors-proxy.herokuapp.com + - Trusted Media Proxy:: _insert the public URL of the Glitch project you Remixed above_ - Latest Update ID:: 5. Make a block with the text `{{[[roam/js]]}}`. diff --git a/telegroam.js b/telegroam.js index 8121d84..429d608 100644 --- a/telegroam.js +++ b/telegroam.js @@ -547,6 +547,7 @@ let nonce = roamAlphaAPI.util.generateUID() + // replace this with your own copy Remixed from glitch.com/~binary-semaphore let lockPath = `https://binary-semaphore.glitch.me/lock/${lockId}/${nonce}` From 7cc9bd57ca10132e1481c9ffa73e13fb2ed718e5 Mon Sep 17 00:00:00 2001 From: cori schlegel <46317+cori@users.noreply.github.com> Date: Fri, 30 Dec 2022 05:58:39 -0600 Subject: [PATCH 5/9] Minor tweaks --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 46a63b9..78fe9e1 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,9 @@ JavaScript plugin for your Roam graph and, your own copy of the proxy implemente ## Prerequisites -You'll need a running instance of [binary-semaphore](https://github.com/cori/binary-semaphore) to point your `roam/js` script to. If you use the address in the `telegroam.js` file you'll be sending your mutex calls through my Glitch instance of that project, with no guarantees for continued maintenance or uptime, but the linked-to repo can help you get set up with your own coy on Glitch. +You'll need a running instance of [binary-semaphore](https://github.com/cori/binary-semaphore) to point your `roam/js` script to. If you use the address in the `telegroam.js` file you'll be sending your mutex calls through an existing Glitch instance of that project, with no guarantees for continued maintenance or uptime, but the linked-to repo can help you get set up with your own copy on Glitch, and there's not much private data to be concerned about in using a shared instance. -You'll also want your own instance of the proxy implemented in _this_ project. Click the button below and you will get a Gllitch Remix of the proxy. You will end up with your -very own proxy URL. +You'll also want your own instance of the proxy implemented in _this_ project. Click the button below and you will get a Glitch Remix of the proxy with your very own proxy URL. [![Remix on Glitch](https://cdn.glitch.com/2703baf2-b643-4da7-ab91-7ee2a2d00b5b%2Fremix-button-v2.svg)](https://glitch.com/edit/#!/remix/telegroam) @@ -27,7 +26,7 @@ because of a bug. Instead we have to download via the proxy server. ## Installation -I will make this more convenient later. +This could be made more convenient.... 1. In Telegram, talk to @BotFather to create a new bot and get an API key for it. From 2e236df3d1563db31916fff6b80d5a154daf6dc9 Mon Sep 17 00:00:00 2001 From: cori schlegel <46317+cori@users.noreply.github.com> Date: Fri, 30 Dec 2022 06:09:04 -0600 Subject: [PATCH 6/9] Update source Glitch project name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 78fe9e1..518808c 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ You'll need a running instance of [binary-semaphore](https://github.com/cori/bin You'll also want your own instance of the proxy implemented in _this_ project. Click the button below and you will get a Glitch Remix of the proxy with your very own proxy URL. -[![Remix on Glitch](https://cdn.glitch.com/2703baf2-b643-4da7-ab91-7ee2a2d00b5b%2Fremix-button-v2.svg)](https://glitch.com/edit/#!/remix/telegroam) +[![Remix on Glitch](https://cdn.glitch.com/2703baf2-b643-4da7-ab91-7ee2a2d00b5b%2Fremix-button-v2.svg)](https://glitch.com/edit/#!/remix/telegroam-proxy) ### Why is a proxy necessary? From 9a0f337e478cb0569fb50b119f0b6b2826d894b6 Mon Sep 17 00:00:00 2001 From: cori schlegel <46317+cori@users.noreply.github.com> Date: Fri, 30 Dec 2022 06:18:15 -0600 Subject: [PATCH 7/9] Clarify installation --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 518808c..bdb97c4 100644 --- a/README.md +++ b/README.md @@ -35,13 +35,14 @@ This could be made more convenient.... 3. Make a page in your Roam called [[Telegram Bot]]. -4. Paste these nodes somewhere on the [[Telegram Bot]] page: - - - Inbox Name:: [[Inbox]] _or whatever page you want these to appear under_ - - API Key:: insert key you get from Telegram's bot system - - {{[[TODO]]}} update the Telegram API key above - - Trusted Media Proxy:: _insert the public URL of the Glitch project you Remixed above_ - - Latest Update ID:: +4. Paste these nodes somewhere on the [[Telegram Bot]] page and replace values as appropriate: + +``` + Inbox Name:: `[[Inbox]] or whatever page you want these to appear under` + API Key:: `insert key you get from Telegram's bot system` + Trusted Media Proxy:: `insert the public URL of the Glitch project you Remixed above` + Latest Update ID:: `leave blank` +``` 5. Make a block with the text `{{[[roam/js]]}}`. From 0f8bb9cabcf361fbb0eae7ded8dd0a33e040bafe Mon Sep 17 00:00:00 2001 From: cori schlegel <46317+cori@users.noreply.github.com> Date: Fri, 30 Dec 2022 06:27:13 -0600 Subject: [PATCH 8/9] Delete yarn.lock --- yarn.lock | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 yarn.lock diff --git a/yarn.lock b/yarn.lock deleted file mode 100644 index 2efafda..0000000 --- a/yarn.lock +++ /dev/null @@ -1,34 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -cors-anywhere@^0.4.4: - version "0.4.4" - resolved "https://registry.yarnpkg.com/cors-anywhere/-/cors-anywhere-0.4.4.tgz#98892fcab55f408fff13a63e125135c18dc22ca8" - integrity sha512-8OBFwnzMgR4mNrAeAyOLB2EruS2z7u02of2bOu7i9kKYlZG+niS7CTHLPgEXKWW2NAOJWRry9RRCaL9lJRjNqg== - dependencies: - http-proxy "1.11.1" - proxy-from-env "0.0.1" - -eventemitter3@1.x.x: - version "1.2.0" - resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-1.2.0.tgz#1c86991d816ad1e504750e73874224ecf3bec508" - integrity sha1-HIaZHYFq0eUEdQ5zh0Ik7PO+xQg= - -http-proxy@1.11.1: - version "1.11.1" - resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.11.1.tgz#71df55757e802d58ea810df2244019dda05ae85d" - integrity sha1-cd9VdX6ALVjqgQ3yJEAZ3aBa6F0= - dependencies: - eventemitter3 "1.x.x" - requires-port "0.x.x" - -proxy-from-env@0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-0.0.1.tgz#b27c4946e9e6d5dbadb7598a6435d3014c4cfd49" - integrity sha1-snxJRunm1dutt1mKZDXTAUxM/Uk= - -requires-port@0.x.x: - version "0.0.1" - resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-0.0.1.tgz#4b4414411d9df7c855995dd899a8c78a2951c16d" - integrity sha1-S0QUQR2d98hVmV3YmajHiilRwW0= From 57c7304f2811e0d72fbe61e42d388592a0462987 Mon Sep 17 00:00:00 2001 From: cori schlegel <46317+cori@users.noreply.github.com> Date: Fri, 30 Dec 2022 06:51:58 -0600 Subject: [PATCH 9/9] README cleanup Add Glitch notes; fiddle around with roam/js formatting --- README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bdb97c4..9efca63 100644 --- a/README.md +++ b/README.md @@ -37,12 +37,10 @@ This could be made more convenient.... 4. Paste these nodes somewhere on the [[Telegram Bot]] page and replace values as appropriate: -``` - Inbox Name:: `[[Inbox]] or whatever page you want these to appear under` - API Key:: `insert key you get from Telegram's bot system` - Trusted Media Proxy:: `insert the public URL of the Glitch project you Remixed above` - Latest Update ID:: `leave blank` -``` + - Inbox Name:: `[[Inbox]] or whatever page you want these to appear under` + - API Key:: `insert key you get from Telegram's bot system` + - Trusted Media Proxy:: `insert the public URL of the Glitch project you Remixed above` + - Latest Update ID:: `leave blank` 5. Make a block with the text `{{[[roam/js]]}}`. @@ -50,3 +48,9 @@ This could be made more convenient.... of `telegroam.js` inside. 7. Reload Roam. + +8. Send a message to your bot. It should appear on your Daily Notes page under the page heading you selected within a few moments. + +## Other notes + +Good news! A single instance of the both the `binary-semaphore` and `telegroam-proxy` projects can handle multiple Roam graphs / Telegram bot combinations. A Roam graph is a consumer of a bot, so multiple graphs can consume the "output" of a single bot by sharing the bot's API key, or each graph can be configured with its own bot key.