| 36 | |
| 37 | // The digest text can come from stdin, --message flag, or --file flag |
| 38 | async function getDigestText() { |
| 39 | const args = process.argv.slice(2); |
| 40 | |
| 41 | // Check --message flag |
| 42 | const msgIdx = args.indexOf('--message'); |
| 43 | if (msgIdx !== -1 && args[msgIdx + 1]) { |
| 44 | return args[msgIdx + 1]; |
| 45 | } |
| 46 | |
| 47 | // Check --file flag |
| 48 | const fileIdx = args.indexOf('--file'); |
| 49 | if (fileIdx !== -1 && args[fileIdx + 1]) { |
| 50 | return await readFile(args[fileIdx + 1], 'utf-8'); |
| 51 | } |
| 52 | |
| 53 | // Read from stdin |
| 54 | const chunks = []; |
| 55 | for await (const chunk of process.stdin) { |
| 56 | chunks.push(chunk); |
| 57 | } |
| 58 | return Buffer.concat(chunks).toString('utf-8'); |
| 59 | } |
| 60 | |
| 61 | // -- Telegram Delivery ------------------------------------------------------- |
| 62 | |