Skip to content
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

Running on Glitch? #31

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .indium.json

This file was deleted.

1 change: 0 additions & 1 deletion Procfile

This file was deleted.

35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@ 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 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 can run your own proxy easily using Heroku's free tier. This is
how I run my proxy.
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.

Click the button below and Heroku will guide you through the whole
thing with zero configuration or coding. 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-proxy)

### Why is a proxy necessary?

Expand All @@ -32,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.
Expand All @@ -41,17 +35,22 @@ I will make this more convenient later.

3. Make a page in your Roam called [[Telegram Bot]].

4. Paste these nodes somewhere on the [[Telegram Bot]] page:
4. Paste these nodes somewhere on the [[Telegram Bot]] page and replace values as appropriate:

- Inbox Name:: [[Inbox]]
- 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
- Latest Update ID::
- 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]]}}`.

6. Nested in that block, make a code block and paste the full contents
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.
5 changes: 0 additions & 5 deletions app.json

This file was deleted.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -18,5 +19,8 @@
"homepage": "https://github.com/mbrock/telegroam#readme",
"dependencies": {
"cors-anywhere": "^0.4.4"
},
"engines": {
"node": "14.x"
}
}
23 changes: 12 additions & 11 deletions telegroam.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -547,15 +547,16 @@
let nonce =
roamAlphaAPI.util.generateUID()

// replace this with your own copy Remixed from glitch.com/~binary-semaphore
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
Expand All @@ -566,7 +567,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
Expand All @@ -581,7 +582,7 @@
}

async function updateFromTelegramContinuously() {
for (;;) {
for (; ;) {
try {
let result = await runWithMutualExclusionLock({
waitSeconds: 30,
Expand Down
34 changes: 0 additions & 34 deletions yarn.lock

This file was deleted.