Skip to content

Commit f0a8629

Browse files
committed
Move Deno example to a separate folder and format with deno fmt
1 parent ab447f1 commit f0a8629

File tree

6 files changed

+148
-38
lines changed

6 files changed

+148
-38
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ An echo bot in multiple languages to get you started.
99
| [C](./c) | `1.132.1` |
1010
| [Go](./go) | `1.127.0` (jsonrpc, newer core might work too, last tested with `v1.131.4` ) |
1111
| [Node.js](./nodejs_stdio_jsonrpc) | `1.139.3` |
12+
| [Deno](./deno) | |
1213
| [Python over cffi](./python_cffi) | `1.132.1` |
1314
| [Python over jsonrpc](./python_jsonrpc) | `1.132.1` |
1415
| [Rust](./rust) | `1.132.1` |

deno/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Echo Bot - Deno
2+
3+
[Deno](https://deno.com/) is an alternative to Node.js. Deno has
4+
[TypeScript](https://www.typescriptlang.org) support out of the box, good
5+
default tooling, and a strict focus on security through it's permission system.
6+
7+
Run the bot with:
8+
9+
```sh
10+
CHATMAIL_QR=dcaccount:https://nine.testrun.org/new deno task start
11+
```

deno/deno.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"tasks": {
3+
"start": "deno run --allow-env --allow-read --allow-run index.js"
4+
},
5+
"imports": {
6+
"@deltachat/jsonrpc-client": "npm:@deltachat/jsonrpc-client@^1.151.3",
7+
"@deltachat/stdio-rpc-server": "npm:@deltachat/stdio-rpc-server@^1.151.3"
8+
}
9+
}

deno/deno.lock

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodejs_stdio_jsonrpc/index_deno.js renamed to deno/index.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//@ts-check
22

3-
import { startDeltaChat } from "https://raw.githubusercontent.com/deltachat/deltachat-core-rust/simon/stdio-jsonrpc-server-npm-package/deltachat-rpc-server/npm-package/index.js";
3+
import { startDeltaChat } from "@deltachat/stdio-rpc-server";
44
import { C } from "@deltachat/jsonrpc-client";
5-
import process from 'node:process'
5+
import process from "node:process";
66

77
async function main() {
88
const dc = await startDeltaChat("deltachat-data");
@@ -12,14 +12,17 @@ async function main() {
1212
// dc.on("ALL", console.debug.bind("[core]"));
1313

1414
// or only log what you want
15-
dc.on("Info", (accountId, { msg }) =>
16-
console.info(accountId, "[core:info]", msg)
15+
dc.on(
16+
"Info",
17+
(accountId, { msg }) => console.info(accountId, "[core:info]", msg),
1718
);
18-
dc.on("Warning", (accountId, { msg }) =>
19-
console.warn(accountId, "[core:warn]", msg)
19+
dc.on(
20+
"Warning",
21+
(accountId, { msg }) => console.warn(accountId, "[core:warn]", msg),
2022
);
21-
dc.on("Error", (accountId, { msg }) =>
22-
console.error(accountId, "[core:error]", msg)
23+
dc.on(
24+
"Error",
25+
(accountId, { msg }) => console.error(accountId, "[core:error]", msg),
2326
);
2427

2528
let firstAccount = (await dc.rpc.getAllAccounts())[0];
@@ -38,7 +41,7 @@ async function main() {
3841
await dc.rpc.setConfigFromQr(firstAccount.id, process.env.CHATMAIL_QR);
3942
} else {
4043
throw new Error(
41-
"Credentials missing, you need to set ADDR and MAIL_PW"
44+
"Credentials missing, you need to set ADDR and MAIL_PW",
4245
);
4346
}
4447
await dc.rpc.batchSetConfig(firstAccount.id, {
@@ -64,7 +67,7 @@ async function main() {
6467
await dc.rpc.miscSendTextMessage(
6568
botAccountId,
6669
chatId,
67-
message.text || ""
70+
message.text || "",
6871
);
6972
}
7073
});
@@ -73,13 +76,15 @@ async function main() {
7376
const verificationQRCode = (
7477
await dc.rpc.getChatSecurejoinQrCodeSvg(botAccountId, null)
7578
)[0];
76-
console.info("".padEnd(40, "="))
79+
console.info("".padEnd(40, "="));
7780
console.info("The email address of your bot is: ", botAddress);
78-
console.info(`Verify Bot contact (if you use chatmail this is nessesary to contact the bot from outside the chatmail instance that the bot uses):
81+
console.info(
82+
`Verify Bot contact (if you use chatmail this is nessesary to contact the bot from outside the chatmail instance that the bot uses):
7983
copy this code and \"scan\" it with delta chat:
8084
81-
${verificationQRCode}`);
82-
console.info("".padEnd(40, "="))
85+
${verificationQRCode}`,
86+
);
87+
console.info("".padEnd(40, "="));
8388
}
8489

8590
main();

nodejs_stdio_jsonrpc/Readme.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,3 @@ CHATMAIL_QR=dcaccount:https://nine.testrun.org/new node .
5555
- [JSON-RPC API documentation](https://jsonrpc.delta.chat/)
5656
- Source code of the JSON-RPC client: https://github.com/deltachat/deltachat-core-rust/blob/main/deltachat-jsonrpc/typescript/
5757
- Source code of the deltachat-rpc-server to JavaScript bindings: https://github.com/deltachat/deltachat-core-rust/blob/main/deltachat-rpc-server/npm-package
58-
59-
### Experimental: Usage with deno instead of node:
60-
61-
Deno (https://deno.com/) is an alternative to nodejs that is better than nodejs in some areas,
62-
such as typescript support out of the box, good default tooling, and a strict focus on security through it's permission system.
63-
64-
For deno the native prebuilds in the npm package do not work (they do not get installed / found),
65-
so you need to install `deltachat-rpc-server` yourself to `$PATH` with:
66-
```sh
67-
cargo install --git https://github.com/deltachat/deltachat-core-rust deltachat-rpc-server
68-
```
69-
Or you download it from the releases page on https://github.com/deltachat/deltachat-core-rust/releases/
70-
and point to it with the `DELTA_CHAT_RPC_SERVER` environment variable:
71-
```sh
72-
# make it executable
73-
chmod +x ./deltachat-rpc-server-aarch64-macos
74-
# set the `DELTA_CHAT_RPC_SERVER` environment variable
75-
export DELTA_CHAT_RPC_SERVER=./deltachat-rpc-server-aarch64-macos
76-
```
77-
78-
run `index_deno.js`:
79-
```sh
80-
CHATMAIL_QR=dcaccount:https://nine.testrun.org/new deno run --allow-env --allow-read --allow-run=deltachat-rpc-server index_deno.js
81-
```

0 commit comments

Comments
 (0)