Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Bridge.prototype.run = function(port, config, appServiceInstance, hostname) {
var self = this;
// Load the registration file into an AppServiceRegistration object.
if (typeof self.opts.registration === "string") {
var regObj = yaml.safeLoad(fs.readFileSync(self.opts.registration, 'utf8'));
self.opts.registration = AppServiceRegistration.fromObject(regObj);
if (self.opts.registration === null) {
throw new Error("Failed to parse registration file");
}
}
this._clientFactory = self.opts.clientFactory || new ClientFactory({
url: self.opts.homeserverUrl,
token: self.opts.registration.as_token,
appServiceUserId: (
"@" + self.opts.registration.sender_localpart + ":" + self.opts.domain
),
clientSchedulerBuilder: function() {
return new MatrixScheduler(retryAlgorithm, queueAlgorithm);
},
});
this._clientFactory.setLogFunction(function(text, isErr) {
}
var botIntentOpts = {
registered: true,
backingStore: this._intentBackingStore,
};
if (this.opts.intentOptions.bot) { // copy across opts
Object.keys(this.opts.intentOptions.bot).forEach(function(k) {
botIntentOpts[k] = self.opts.intentOptions.bot[k];
});
}
this._botIntent = new Intent(this._botClient, this._botClient, botIntentOpts);
this._intents = {
// user_id + request_id : Intent
};
this.appService = appServiceInstance || new AppService({
homeserverToken: this.opts.registration.getHomeserverToken()
});
this.appService.onUserQuery = (userId) => Promise.cast(this._onUserQuery(userId));
this.appService.onAliasQuery = this._onAliasQuery.bind(this);
this.appService.on("event", this._onEvent.bind(this));
this.appService.on("http-log", function(line) {
if (!self.opts.controller.onLog) {
return;
}
self.opts.controller.onLog(line, false);
});
this._customiseAppservice();
this._setupIntentCulling();
if (this._metrics) {
this._metrics.addAppServicePath(this);
Cli.prototype._generateRegistration = function(appServiceUrl, localpart) {
if (!appServiceUrl) {
throw new Error("Missing app service URL");
}
var self = this;
var reg = new AppServiceRegistration(appServiceUrl);
if (localpart) {
reg.setSenderLocalpart(localpart);
}
this.opts.generateRegistration.bind(this)(reg, function(completeReg) {
reg = completeReg;
reg.outputAsYaml(self.opts.registrationPath);
console.log("Output registration to: " + self.opts.registrationPath);
process.exit(0);
});
};
generateRegistration: function(appServiceUrl, callback) {
var reg = new AppServiceRegistration(appServiceUrl);
reg.setHomeserverToken(AppServiceRegistration.generateToken());
reg.setAppServiceToken(AppServiceRegistration.generateToken());
reg.setSenderLocalpart("vertobot");
reg.addRegexPattern("users", "@" + USER_PREFIX + ".*", true);
console.log(
"Generating registration to '%s' for the AS accessible from: %s",
REGISTRATION_FILE, appServiceUrl
);
callback(reg);
},
run: runBridge
generateRegistration: function(callback) {
var reg = new AppServiceRegistration("http://localhost:8008");
reg.setHomeserverToken(AppServiceRegistration.generateToken());
reg.setAppServiceToken(AppServiceRegistration.generateToken());
reg.setSenderLocalpart("bridge-example");
reg.addRegexPattern("users", "@example_.*", true);
console.log("Generating registration to 'my-bridge-registration.yaml'");
callback(reg);
}
});
generateRegistration: function(callback) {
var reg = new AppServiceRegistration("http://localhost:8008");
reg.setHomeserverToken(AppServiceRegistration.generateToken());
reg.setAppServiceToken(AppServiceRegistration.generateToken());
reg.setSenderLocalpart("bridge-example");
reg.addRegexPattern("users", "@example_.*", true);
console.log("Generating registration to 'my-bridge-registration.yaml'");
callback(reg);
}
});
generateRegistration: function(appServiceUrl, callback) {
var reg = new AppServiceRegistration(appServiceUrl);
reg.setHomeserverToken(AppServiceRegistration.generateToken());
reg.setAppServiceToken(AppServiceRegistration.generateToken());
reg.setSenderLocalpart("vertobot");
reg.addRegexPattern("users", "@" + USER_PREFIX + ".*", true);
console.log(
"Generating registration to '%s' for the AS accessible from: %s",
REGISTRATION_FILE, appServiceUrl
);
callback(reg);
},
run: runBridge
generateRegistration: function(appServiceUrl, callback) {
var reg = new AppServiceRegistration(appServiceUrl);
reg.setHomeserverToken(AppServiceRegistration.generateToken());
reg.setAppServiceToken(AppServiceRegistration.generateToken());
reg.setSenderLocalpart("vertobot");
reg.addRegexPattern("users", "@" + USER_PREFIX + ".*", true);
console.log(
"Generating registration to '%s' for the AS accessible from: %s",
REGISTRATION_FILE, appServiceUrl
);
callback(reg);
},
run: runBridge
generateRegistration: function(callback) {
var reg = new AppServiceRegistration("http://localhost:8008");
reg.setHomeserverToken(AppServiceRegistration.generateToken());
reg.setAppServiceToken(AppServiceRegistration.generateToken());
reg.setSenderLocalpart("bridge-example");
reg.addRegexPattern("users", "@example_.*", true);
console.log("Generating registration to 'my-bridge-registration.yaml'");
callback(reg);
}
});
if (!appService._events[name]) {
appService._events[name] = [];
}
appService._events[name].push(fn);
});
appService.emit = function(name, obj) {
var list = appService._events[name] || [];
var promises = list.map(function(fn) {
return fn(obj);
});
return Promise.all(promises);
};
bridgeCtrl = jasmine.createSpyObj("controller", [
"onEvent", "onAliasQuery", "onUserQuery"
]);
appServiceRegistration = AppServiceRegistration.fromObject({
id: "an_id",
hs_token: "h5_t0k3n",
as_token: "a5_t0k3n",
url: "http://app-service-url",
sender_localpart: BOT_LOCALPART,
namespaces: {
users: [{
exclusive: true,
regex: "@virtual_.*"
}],
aliases: [{
exclusive: true,
regex: "#virtual_.*"
}]
}
});