-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathonCommand-webhook.js
71 lines (54 loc) · 2.96 KB
/
onCommand-webhook.js
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
61
62
63
64
65
66
67
68
//
// Copyright (c) 2016-2019 Cisco Systems
// Licensed under the MIT License
//
/*
* a Webex Teams webhook that leverages a simple library (batteries included)
*
* note : this example requires that you've set an ACCESS_TOKEN env variable
*
*/
var SparkBot = require("../sparkbot/webhook");
// Starts your Webhook with default configuration where the Webex Teams API access token is read from the ACCESS_TOKEN env variable
var bot = new SparkBot();
// Registers the bot to the Webex Teams Service to start receiving notifications
// We list here various options to register your bot: pick one and update the code with your bot name and its public endpoint
// Simplissime registration where defaults apply (all, all, no filter, no secret), and no callback
//bot.createOrUpdateWebhook("register-bot", "https://f6d5d937.ngrok.io");
// Registration without any filter, secret, and callback
//bot.createOrUpdateWebhook("register-bot", "https://f6d5d937.ngrok.io", "all", "all");
// Registration with a filter, no secret, no callback
//bot.createOrUpdateWebhook("register-bot", "https://f6d5d937.ngrok.io", "all", "all", "roomId=XXXXXXXXXXXXXXX");
// Registration with no filter, but a secret and a callback
// note that the secret needs to be known to the bot so that it can check the payload signatures
var publicURL = process.env.PUBLIC_URL || "https://f6d5d937.ngrok.io";
bot.secret = process.env.WEBHOOK_SECRET || "not THAT secret";
bot.createOrUpdateWebhook("register-bot", publicURL, "all", "all", null, bot.secret, function (err, webhook) {
if (err) {
console.error("could not create Webhook, err: " + err);
// Fail fast
process.exit(1);
}
console.log("webhook successfully checked, with id: " + webhook.id);
});
// Registration with no filter, but a secret and a callback
// bot name and public endpoint are read from env variables, the WEBHOOK_SECRET env variable is used to initialize the secret
// make sure to initialize these env variables
// - BOT_NAME="register-bot"
// - WEBHOOK_SECRET="not THAT secret"
// - PUBLIC_URL="https://f6d5d937.ngrok.io"
// example:
// DEBUG=sparkbot* BOT_NAME="register-bot" PUBLIC_URL="https://f6d5d937.ngrok.io" WEBHOOK_SECRET="not THAT secret" ACCESS_TOKEN="MjdkYjRhNGItM2E1ZS00YmZjLTk2ZmQtO" node tests/onCommand-register.js
//bot.createOrUpdateWebhook(process.env.BOT_NAME, process.env.PUBLIC_URL, "all", "all", null, bot.secret, function (err, webhook) {
// if (err) {
// console.log("Could not register the bot, please check your env variables are all set: ACCESS_TOKEN, BOT_NAME, PUBLIC_URL");
// return;
// }
// console.log("webhook successfully created, id: " + webhook.id);
//});
// Override default prefix "/" to "" so that our bot will obey to "help"" instead of "/help"
bot.interpreter.prefix="";
bot.onCommand("help", function(command) {
// ADD YOUR CUSTOM CODE HERE
console.log("new command: " + command.keyword + ", from: " + command.message.personEmail + ", with args: " + JSON.stringify(command.args));
});