From 5dc02ac1b28d4dff79cf60f403fd172f66ced372 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Wed, 2 Dec 2020 00:23:58 -0500 Subject: [PATCH] change ari to ami in intercom --- package.json | 1 + src/commands/intercom.ts | 32 +++++++++++++------------------- src/commands/sysinfo.ts | 3 ++- types/index.d.ts | 1 + yarn.lock | 14 +++++++++++++- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 90a3083..b14fa4e 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "dependencies": { "@google-cloud/text-to-speech": "^3.1.2", "ari-client": "^2.2.0", + "asterisk-manager": "^0.1.16", "awesome-phonenumber": "^2.41.0", "axios": "^0.19.2", "body-parser": "^1.19.0", diff --git a/src/commands/intercom.ts b/src/commands/intercom.ts index 460058d..9b537ca 100644 --- a/src/commands/intercom.ts +++ b/src/commands/intercom.ts @@ -20,28 +20,22 @@ export default class Intercom extends Command { const recordingLocation = await MiscPBXActions.TTS(this.client.util.pbx, `Hello, this is the Library of Code Private Branch Exchange dialing you at the request of ${message.author.username} to deliver you a message. Playing message: ${args.slice(1).join(' ')}`, 'MALE'); await loading.edit(`***${this.client.util.emojis.LOADING} Preparing to dial...***`); - const channel = await this.client.util.ari.channels.originate({ - endpoint: `PJSIP/${args[0]}`, - extension: args[0], - callerId: `TTS PAGE FRM ${message.author.username} <00>`, - priority: 1, - app: 'cr-zero', - variables: { + this.client.util.ami.action({ + action: 'originate', + channel: `PJSIP/${args[0]}`, + exten: args[0], + context: 'from-internal', + CallerID: `TTS PAGE FRM ${message.author.username} <*0>`, + application: 'PlayBack', + priority: '1', + data: `beep&${recordingLocation}`, + variable: { 'PJSIP_HEADER(add,Call-Info)': ';answer-after=0', 'PJSIP_HEADER(add,Alert-Info)': 'Ring Answer', }, - }); - await loading.edit(`***${this.client.util.emojis.LOADING} Dialing call...***`); - channel.once('StasisStart', async (_, chan) => { - chan.answer(); - await loading.edit(`***${this.client.util.emojis.LOADING} Answer received, starting playback...***`); - const playback = await chan.play({ - media: ['sound:beep', recordingLocation], - }, undefined); - playback.once('PlaybackFinished', async () => { - chan.hangup(); - await loading.edit(`***${this.client.util.emojis.LOADING} Successfully delivered intercom message to EXT \`${args[0]}\`.***`); - }); + }, async (err: Error) => { + if (err) return loading.edit(`***${this.client.util.emojis.ERROR} Failed to dial extension. | ${err}`); + return loading.edit(`***${this.client.util.emojis.SUCCESS} Successfully queued intercom message to EXT \`${args[0]}\`.***`); }); return undefined; } catch (err) { diff --git a/src/commands/sysinfo.ts b/src/commands/sysinfo.ts index 3abca1c..22943c0 100644 --- a/src/commands/sysinfo.ts +++ b/src/commands/sysinfo.ts @@ -6,6 +6,7 @@ import { Client, Command, RichEmbed } from '../class'; import { version as erisVersion } from '../../node_modules/eris/package.json'; import { version as mongooseVersion } from '../../node_modules/mongoose/package.json'; import { version as ariVersion } from '../../node_modules/ari-client/package.json'; +import { version as amiVersion } from '../../node_modules/asterisk-manager/package.json'; import { version as nodeMailerVersion } from '../../node_modules/nodemailer/package.json'; import { version as ioredisVersion } from '../../node_modules/ioredis/package.json'; import { version as stripeVersion } from '../../node_modules/stripe/package.json'; @@ -37,7 +38,7 @@ export default class SysInfo extends Command { const asteriskInformation = await this.client.util.ari.asterisk.getInfo(); const redisVersion = await this.client.util.exec('redis-cli info | grep "redis_version"'); embed.addField('Database', `- [MongoDB v${mongoBuild.version}](https://www.mongodb.com/) + Documents: ${mongoDatabase.objects} | [Mongoose ODM v${mongooseVersion}](https://github.com/Automattic/mongoose)\n- CR Local Storage w/ GZIP Compression | Internal\n- [Redis v${redisVersion.split(':')[1]}](https://redis.io/) | [IORedis v${ioredisVersion}](https://github.com/luin/ioredis)`, true); - embed.addField('Telephony/PBX', `- [Asterisk v${asteriskInformation.system.version}](https://www.asterisk.org/) | [Asterisk ARI Node.js Client v${ariVersion}](https://github.com/asterisk/node-ari-client)`, true); + embed.addField('Telephony/PBX', `- [Asterisk v${asteriskInformation.system.version}](https://www.asterisk.org/) | [Asterisk ARI Node.js Client v${ariVersion}](https://github.com/asterisk/node-ari-client) & [Asterisk AMI Node.js Client v${amiVersion}](https://github.com/danjenkins/node-asterisk-ami)`, true); embed.addField('Email', `- [Postfix SMTP v3.1.12](http://www.postfix.org/) | [Nodemailer v${nodeMailerVersion}](https://github.com/nodemailer/nodemailer)`, true); embed.addField('Discord', `- N/A | [Eris v${erisVersion}](https://github.com/abalabahaha/eris)`, true); embed.addField('Payments', `- [Stripe API](https://stripe.com/) | [Stripe Node.js Client v${stripeVersion}](https://github.com/stripe/stripe-node)`, true); diff --git a/types/index.d.ts b/types/index.d.ts index 8754d81..eff940e 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -10,4 +10,5 @@ export declare interface Config { stripeKey: string; stripeSubSigningSecret: string; ariClientKey: string; + amiClientKey: string; } diff --git a/yarn.lock b/yarn.lock index 137582c..894b126 100644 --- a/yarn.lock +++ b/yarn.lock @@ -537,6 +537,11 @@ assert-plus@1.0.0, assert-plus@^1.0.0: resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525" integrity sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU= +asterisk-manager@^0.1.16: + version "0.1.16" + resolved "https://registry.yarnpkg.com/asterisk-manager/-/asterisk-manager-0.1.16.tgz#4afc7d669e0ae86f24d2d18b7d91c9fa7044fc36" + integrity sha512-JxcgSutGhz6B2XtYkqkOI/sRH3hCGHmeNXuqNBw1JMtDMrRzpfuXB0keH4ouRtQPxdb2LIj83RWdR5uVnFim9A== + astral-regex@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9" @@ -611,7 +616,7 @@ bignumber.js@^9.0.0: resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.0.1.tgz#8d7ba124c882bfd8e43260c67475518d0689e4e5" integrity sha512-IdZR9mh6ahOBv/hYGiXyVuyCetmGJhtYkqLBpTStdhEGjegpPlUawydyaF3pbIOFynJTpllEs+NP+CS9jKFLjA== -bindings@^1.5.0: +bindings@1.5.0, bindings@^1.5.0: version "1.5.0" resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df" integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ== @@ -3339,6 +3344,13 @@ saslprep@^1.0.0: dependencies: sparse-bitfield "^3.0.3" +sd-notify@^2.8.0: + version "2.8.0" + resolved "https://registry.yarnpkg.com/sd-notify/-/sd-notify-2.8.0.tgz#a8e4477efac8426084e235d5d6a89f2af75571fd" + integrity sha512-e+D1v0Y6UzmqXcPlaTkHk1QMdqk36mF/jIYv5gwry/N2Tb8/UNnpfG6ktGLpeBOR6TCC5hPKgqA+0hTl9sm2tA== + dependencies: + bindings "1.5.0" + seed-random@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/seed-random/-/seed-random-2.2.0.tgz#2a9b19e250a817099231a5b99a4daf80b7fbed54"