send queue leave webhook when dequeued

This commit is contained in:
Dave Horton
2021-06-17 15:52:46 -04:00
parent bb0ec8e184
commit 08c53aa586
2 changed files with 17 additions and 2 deletions

View File

@@ -110,7 +110,8 @@ class TaskDequeue extends Task {
event: 'dequeue', event: 'dequeue',
dequeueSipAddress: cs.srf.locals.localSipAddress, dequeueSipAddress: cs.srf.locals.localSipAddress,
epUuid: ep.uuid, epUuid: ep.uuid,
notifyUrl: getUrl(cs) notifyUrl: getUrl(cs),
dequeuer: cs.callInfo.toJSON()
}); });
this.logger.info(`TaskDequeue:_dequeueUrl successfully sent POST to ${url}`); this.logger.info(`TaskDequeue:_dequeueUrl successfully sent POST to ${url}`);
bridgeTimer = setTimeout(() => reject(new Error('bridge timeout')), 20000); bridgeTimer = setTimeout(() => reject(new Error('bridge timeout')), 20000);

View File

@@ -263,12 +263,26 @@ class TaskEnqueue extends Task {
* @param {string} opts.epUuid uuid of the endpoint we need to bridge to * @param {string} opts.epUuid uuid of the endpoint we need to bridge to
* @param {string} opts.dequeueSipAddress ip:port of the feature server hosting the other call * @param {string} opts.dequeueSipAddress ip:port of the feature server hosting the other call
*/ */
notifyQueueEvent(cs, opts) { async notifyQueueEvent(cs, opts) {
if (opts.event === 'dequeue') { if (opts.event === 'dequeue') {
if (this.bridgeNow) return; if (this.bridgeNow) return;
this.logger.info({opts}, `TaskEnqueue:notifyDequeueEvent: leaving ${this.queueName} because someone wants me`); this.logger.info({opts}, `TaskEnqueue:notifyDequeueEvent: leaving ${this.queueName} because someone wants me`);
assert(opts.dequeueSipAddress && opts.epUuid && opts.notifyUrl); assert(opts.dequeueSipAddress && opts.epUuid && opts.notifyUrl);
this.emitter.emit('dequeue', opts); this.emitter.emit('dequeue', opts);
try {
const {lengthOfList} = cs.srf.locals.dbHelpers;
const members = await lengthOfList(this.queueName);
cs.performQueueWebhook({
event: 'leave',
queue: this.data.name,
length: Math.max(members - 1, 0),
leaveReason: 'dequeued',
leaveTime: Date.now(),
dequeuer: opts.dequeuer
});
} catch (err) {}
} }
else if (opts.event === 'hangup') { else if (opts.event === 'hangup') {
this.emitter.emit('hangup'); this.emitter.emit('hangup');