Spaces:
Runtime error
Runtime error
File size: 1,608 Bytes
4327358 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
// eslint-disable-next-line @typescript-eslint/no-var-requires
const axios = require('axios');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const yargs = require('yargs/yargs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { hideBin } = require('yargs/helpers');
// Parse CLI arguments
const argv = yargs(hideBin(process.argv))
.option('number', {
alias: 'n',
type: 'number',
description: 'Number of messages to send',
default: 10,
})
.option('chat-id', {
alias: 'to',
type: 'number',
description: 'Chat ID to send messages to',
demandOption: true,
})
.option('session', {
type: 'string',
description: 'Session ID to use',
demandOption: true,
})
.option('api-key', {
alias: 'k',
type: 'string',
description: 'API key for authentication',
demandOption: true,
})
.help().argv;
const sendTextMessage = async (session, numMessages, chatId, apiKey) => {
const url = 'http://localhost:3000/api/sendText/';
for (let i = 1; i <= numMessages; i++) {
console.log(`Sending message ${i}`);
const response = await axios.post(
url,
{
chatId: chatId.toString(),
session: session,
text: `Message - ${i}`,
},
{
headers: {
Accept: 'application/json',
'X-Api-Key': apiKey,
'Content-Type': 'application/json',
},
},
);
console.log(`Message ${i} sent successfully:`, response.data);
}
};
// Run the script
sendTextMessage(argv.session, argv.number, argv['chat-id'], argv['api-key']);
|