Bring in node-signald
This commit is contained in:
parent
26bd446368
commit
41971732d0
13 changed files with 3474 additions and 0 deletions
73
packages/node-signald/example/example.ts
Normal file
73
packages/node-signald/example/example.ts
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
import { SignaldAPI, CaptchaRequiredException } from "node-signald";
|
||||
import * as process from "process";
|
||||
import * as prompt from "prompt";
|
||||
|
||||
const SOCKETFILE =
|
||||
process.env.SIGNALD_SOCKET || "/run/user/1000/signald/signald.sock";
|
||||
|
||||
const validate = () => {
|
||||
if (!process.env.NUMBER)
|
||||
throw new Error(
|
||||
"Please set the NUMBER env var to the number you want to test with."
|
||||
);
|
||||
};
|
||||
const main = async () => {
|
||||
validate();
|
||||
const signald = new SignaldAPI();
|
||||
await signald.connectAsync(SOCKETFILE);
|
||||
try {
|
||||
await signald.register(process.env.NUMBER);
|
||||
} catch (e) {
|
||||
console.log("GOT A error", e.name);
|
||||
if (e.name === "CaptchaRequiredException") {
|
||||
console.log(`
|
||||
|
||||
CAPTCHA REQUIRED
|
||||
-----------------
|
||||
|
||||
1. Visit https://signalcaptchas.org/registration/generate.html
|
||||
2. Appease the machine
|
||||
3. Bring back your captcha gobbly-gook here
|
||||
`);
|
||||
console.log("captcha required");
|
||||
|
||||
prompt.start();
|
||||
const { captcha } = await prompt.get(["captcha"]);
|
||||
await signald.register(process.env.NUMBER, false, captcha);
|
||||
} else {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
const { code } = await prompt.get(["code"]);
|
||||
await signald.verify(process.env.NUMBER, code);
|
||||
};
|
||||
|
||||
const main2 = async () => {
|
||||
validate();
|
||||
const signald = new SignaldAPI();
|
||||
await signald.connectAsync(SOCKETFILE);
|
||||
let result = await signald.listAccounts();
|
||||
console.log(JSON.stringify(result));
|
||||
signald.on("messagev0", (envelope) => {
|
||||
const source = envelope.source.number;
|
||||
const body = envelope.dataMessage.body;
|
||||
const when = new Date(envelope.timestamp).toDateString();
|
||||
console.log(`${when} [${source}]: ${body}`);
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
result.accounts.map(
|
||||
async (account: any) => await signald.requestSync(account.address.uuid)
|
||||
)
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
result.accounts.map(
|
||||
async (account: any) => await signald.subscribev0(account.address.uuid)
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
// main();
|
||||
main2();
|
||||
20
packages/node-signald/example/package.json
Normal file
20
packages/node-signald/example/package.json
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "node-signald-example",
|
||||
"version": "0.0.1",
|
||||
"description": "example usage",
|
||||
"main": "index.js",
|
||||
"license": "AGPL-3.0-only",
|
||||
"private": false,
|
||||
"scripts": {
|
||||
"example": "node --unhandled-rejections=strict -r ts-node/register --unhandled-rejections=strict example.ts",
|
||||
"linklib": "cd ../ && yarn build && yarn link && cd example && yarn link node-signald"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ts-node": "^10.0.0",
|
||||
"typescript": "^4.3.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"prompt": "^1.1.0",
|
||||
"uuid": "^8.3.2"
|
||||
}
|
||||
}
|
||||
27
packages/node-signald/example/tsconfig.json
Normal file
27
packages/node-signald/example/tsconfig.json
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"incremental": true,
|
||||
"module": "commonjs",
|
||||
"target": "es2019",
|
||||
"lib": ["es2020"],
|
||||
"declaration": true,
|
||||
"esModuleInterop": true,
|
||||
"outDir": "./dist",
|
||||
"types": ["node", "jest"],
|
||||
|
||||
"moduleResolution": "node",
|
||||
"inlineSourceMap": true,
|
||||
"resolveJsonModule": true,
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"traceResolution": false,
|
||||
"listEmittedFiles": false,
|
||||
"listFiles": false,
|
||||
"pretty": true,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true
|
||||
},
|
||||
"include": ["example.ts"]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue