Created
July 8, 2022 06:44
-
-
Save whatsmate/a6b6c46cf6dbdf85f2a7d4405ebcfe7c to your computer and use it in GitHub Desktop.
How to send a voice note file to a Telegram group in Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env node | |
| var http = require('http'); | |
| var fs = require('fs'); | |
| // Put down your own client ID and secret here: | |
| var instanceId = "YOUR_OWN_GATEWAY_INSTANCE_ID"; | |
| var clientId = "YOUR_OWN_CLIENT_ID"; | |
| var clientSecret = "YOUR_OWN_SECRET_ID"; | |
| var jsonPayload = JSON.stringify({ | |
| group_name: "Muscle Men Club", // TODO: Specify the group name here. | |
| group_admin: "19159876123", // TODO: Specify the number of the group admin here. | |
| voice_note: fs.readFileSync("../assets/martin-luther-king.mp3").toString('base64'), // FIXME | |
| filename: "anyname.opus", // FIXME | |
| caption: "I have a dream" // FIXME | |
| }); | |
| var options = { | |
| hostname: "api.whatsmate.net", | |
| port: 80, | |
| path: "/v3/telegram/group/voice_note/message/" + instanceId, | |
| method: "POST", | |
| headers: { | |
| "Content-Type": "application/json", | |
| "X-WM-CLIENT-ID": clientId, | |
| "X-WM-CLIENT-SECRET": clientSecret, | |
| "Content-Length": Buffer.byteLength(jsonPayload) | |
| } | |
| }; | |
| var request = new http.ClientRequest(options); | |
| request.end(jsonPayload); | |
| request.on('response', function (response) { | |
| console.log('Heard back from WhatsMate Telegram Gateway:\n'); | |
| console.log('Status code: ' + response.statusCode); | |
| response.setEncoding('utf8'); | |
| response.on('data', function (chunk) { | |
| console.log(chunk); | |
| }); | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Write-up: https://whatsmate.github.io/2022-06-29-send-telegram-group-voice-note-nodejs-javascript/