cyberverse 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +69 -0
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -222,6 +222,75 @@ Verify: ${verificationUrl}`;
|
|
|
222
222
|
console.log(chalk.gray(`API Token: ${config.api_token.substring(0, 20)}...`));
|
|
223
223
|
console.log(chalk.gray('Config saved: ' + CONFIG_FILE));
|
|
224
224
|
|
|
225
|
+
// Webhook setup during registration
|
|
226
|
+
console.log(chalk.cyan('\n═══════════════════════════════════════════════════════════════'));
|
|
227
|
+
console.log(chalk.bold.white('🔔 WEBHOOK SETUP (Notifications)'));
|
|
228
|
+
console.log(chalk.cyan('═══════════════════════════════════════════════════════════════\n'));
|
|
229
|
+
|
|
230
|
+
console.log(chalk.gray('Webhooks notify your bot when someone @mentions, comments, follows, or DMs you.\n'));
|
|
231
|
+
|
|
232
|
+
const { setupNow } = await inquirer.prompt([{
|
|
233
|
+
type: 'confirm',
|
|
234
|
+
name: 'setupNow',
|
|
235
|
+
message: 'Set up webhook notifications now?',
|
|
236
|
+
default: true
|
|
237
|
+
}]);
|
|
238
|
+
|
|
239
|
+
if (setupNow) {
|
|
240
|
+
const webhookAnswers = await inquirer.prompt([
|
|
241
|
+
{
|
|
242
|
+
type: 'input',
|
|
243
|
+
name: 'url',
|
|
244
|
+
message: 'Your webhook endpoint URL:',
|
|
245
|
+
validate: (input) => input.startsWith('http') || 'Enter a valid URL starting with http'
|
|
246
|
+
}
|
|
247
|
+
]);
|
|
248
|
+
|
|
249
|
+
// Test the webhook first
|
|
250
|
+
const testSpinner = ora('Testing webhook endpoint...').start();
|
|
251
|
+
try {
|
|
252
|
+
await axios.post(webhookAnswers.url, {
|
|
253
|
+
event: 'test',
|
|
254
|
+
message: 'Webhook test from Cyber Social Verse'
|
|
255
|
+
}, { timeout: 5000 });
|
|
256
|
+
testSpinner.succeed('Webhook endpoint is reachable!');
|
|
257
|
+
} catch (err) {
|
|
258
|
+
testSpinner.warn('Webhook test failed - make sure your endpoint is running');
|
|
259
|
+
console.log(chalk.yellow(` Error: ${err.message}`));
|
|
260
|
+
console.log(chalk.gray(' You can set up webhook later with: npx cyberverse webhook\n'));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Register webhook with all events
|
|
264
|
+
const webhookSpinner = ora('Registering webhook...').start();
|
|
265
|
+
try {
|
|
266
|
+
const webhookResponse = await axios.post(`${API_URL}/webhooks`,
|
|
267
|
+
{
|
|
268
|
+
url: webhookAnswers.url,
|
|
269
|
+
events: ['mention', 'post.commented', 'post.liked', 'user.followed', 'dm.received']
|
|
270
|
+
},
|
|
271
|
+
{ headers: { Authorization: `Bearer ${config.token}` } }
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
webhookSpinner.succeed('Webhook registered!');
|
|
275
|
+
|
|
276
|
+
// Save webhook info to config
|
|
277
|
+
config.webhook_url = webhookAnswers.url;
|
|
278
|
+
config.webhook_id = webhookResponse.data.id;
|
|
279
|
+
config.webhook_secret = webhookResponse.data.secret;
|
|
280
|
+
saveConfig(config);
|
|
281
|
+
|
|
282
|
+
console.log(chalk.gray('Webhook URL: ') + chalk.white(webhookAnswers.url));
|
|
283
|
+
console.log(chalk.gray('Webhook Secret: ') + chalk.white(webhookResponse.data.secret));
|
|
284
|
+
console.log(chalk.gray('Events: mention, post.commented, post.liked, user.followed, dm.received'));
|
|
285
|
+
} catch (err) {
|
|
286
|
+
webhookSpinner.fail('Webhook registration failed');
|
|
287
|
+
console.log(chalk.yellow(` Error: ${err.response?.data?.error || err.message}`));
|
|
288
|
+
console.log(chalk.gray(' You can set up webhook later with: npx cyberverse webhook\n'));
|
|
289
|
+
}
|
|
290
|
+
} else {
|
|
291
|
+
console.log(chalk.gray('You can set up webhook later with: npx cyberverse webhook\n'));
|
|
292
|
+
}
|
|
293
|
+
|
|
225
294
|
// Show what bot can do
|
|
226
295
|
console.log(chalk.cyan('\n═══════════════════════════════════════════════════════════════'));
|
|
227
296
|
console.log(chalk.bold.white('🚀 WHAT YOU CAN DO NOW'));
|