diff options
| author | Adam Soltys <[email protected]> | 2023-07-13 01:03:36 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-07-13 01:03:36 -0700 |
| commit | d18b06483a4b62b2d871d8c3cbbc5be4dec042fc (patch) | |
| tree | 26b90525775e67d2173652fc791fcdf9e85e9259 | |
| parent | a30f2b4bc85ff9823e9c03fbfaae1685d081d708 (diff) | |
| download | coinos-server-d18b06483a4b62b2d871d8c3cbbc5be4dec042fc.tar.gz coinos-server-d18b06483a4b62b2d871d8c3cbbc5be4dec042fc.zip | |
text to speech notification
| -rw-r--r-- | lib/app.js | 2 | ||||
| -rw-r--r-- | lib/payments.js | 16 | ||||
| -rw-r--r-- | package.json | 1 | ||||
| -rw-r--r-- | pnpm-lock.yaml | 8 |
4 files changed, 25 insertions, 2 deletions
@@ -42,7 +42,7 @@ app.register(fastifyWs, { } }); -await fastify.register(cors, { +await app.register(cors, { origin: true }); diff --git a/lib/payments.js b/lib/payments.js index e1e0590e..2d322a15 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -7,6 +7,8 @@ import { db, g, s, t } from "$lib/db"; import { l, err, warn } from "$lib/logging"; import { fail } from "$lib/utils"; import { callWebhook } from "$lib/webhooks"; +import dollarsToWords from "dollars-to-words"; +import got from "got"; export const types = { internal: "internal", @@ -122,7 +124,6 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { let equivalentRate = invoice.rate * (store.rates[currency] / store.rates[invoice.currency]); - if (Math.abs(invoice.rate / store.rates[invoice.currency] - 1) < 0.01) { rate = equivalentRate; } else { @@ -171,6 +172,19 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { emit(uid, "payment", p); notify(user, `Received ${amount} sats`); callWebhook(invoice, p); + if (user.username === "bob") { + let words = dollarsToWords( + parseFloat(((amount * p.rate) / 100000000).toFixed(2)) + ); + + try { + let r = await got + .post("http://172.42.0.1:4020/tts", { json: { words, name: p.id } }) + .json(); + } catch (e) { + console.log(e); + } + } return p; }; diff --git a/package.json b/package.json index af18d924..a0cb82e9 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "bech32": "^2.0.0", "clightning-client": "github:SimonVrouwe/lightning-client-js#2022-11-04_improve_doc", "date-fns": "^2.21.3", + "dollars-to-words": "github:asoltys/dollars-to-words", "fastify": "^4.5.3", "file-type": "^18.0.0", "got": "^12.5.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index abee9748..f3f92e0e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,6 +12,7 @@ specifiers: bech32: ^2.0.0 clightning-client: github:SimonVrouwe/lightning-client-js#2022-11-04_improve_doc date-fns: ^2.21.3 + dollars-to-words: github:asoltys/dollars-to-words fastify: ^4.5.3 file-type: ^18.0.0 got: ^12.5.3 @@ -46,6 +47,7 @@ dependencies: bech32: 2.0.0 clightning-client: github.com/SimonVrouwe/lightning-client-js/946642bafca572fb5d9ce2dc1316d415fa950a05 date-fns: 2.29.3 + dollars-to-words: github.com/asoltys/dollars-to-words/2139443f523facf106d2fbfa7571d1b63cd26f37 fastify: 4.8.1 file-type: 18.0.0 got: 12.5.3 @@ -3466,3 +3468,9 @@ packages: transitivePeerDependencies: - supports-color dev: false + + github.com/asoltys/dollars-to-words/2139443f523facf106d2fbfa7571d1b63cd26f37: + resolution: {tarball: https://codeload.github.com/asoltys/dollars-to-words/tar.gz/2139443f523facf106d2fbfa7571d1b63cd26f37} + name: dollars-to-words + version: 1.1.1 + dev: false |
