@gibme/asterisk-gateway-interface 1.0.1

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.
@@ -0,0 +1,41 @@
1
+ export interface IResponseArguments {
2
+ key: string;
3
+ value: string | number | boolean;
4
+ }
5
+ /**
6
+ * Represents a set of AGI response arguments
7
+ * @ignore
8
+ */
9
+ export default class ResponseArguments {
10
+ private m_args;
11
+ /**
12
+ * Adds a new argument to the set
13
+ * @param key
14
+ * @param value
15
+ */
16
+ addArgument(key: string, value: string | number | boolean): void;
17
+ /**
18
+ * Retrieves the requested key as a string
19
+ * @param key
20
+ */
21
+ string(key: string): string;
22
+ /**
23
+ * Retrieves the requested key as a number
24
+ * @param key
25
+ */
26
+ number(key: string): number;
27
+ /**
28
+ * Retrieves the request key as a boolean
29
+ * @param key
30
+ */
31
+ boolean(key: string): boolean;
32
+ /**
33
+ * Retrieves the requested key from a character code
34
+ * @param key
35
+ */
36
+ char(key: string): string;
37
+ /**
38
+ * Retrieves the value from the arguments that has no key, if it exists
39
+ */
40
+ nokey(): string;
41
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ // Copyright (c) 2016-2022 Brandon Lehmann
3
+ //
4
+ // Please see the included LICENSE file for more information.
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ /**
7
+ * Represents a set of AGI response arguments
8
+ * @ignore
9
+ */
10
+ class ResponseArguments {
11
+ constructor() {
12
+ this.m_args = [];
13
+ }
14
+ /**
15
+ * Adds a new argument to the set
16
+ * @param key
17
+ * @param value
18
+ */
19
+ addArgument(key, value) {
20
+ this.m_args.push({ key, value });
21
+ }
22
+ /**
23
+ * Retrieves the requested key as a string
24
+ * @param key
25
+ */
26
+ string(key) {
27
+ for (const arg of this.m_args) {
28
+ if (arg.key === key) {
29
+ return arg.value;
30
+ }
31
+ }
32
+ return '';
33
+ }
34
+ /**
35
+ * Retrieves the requested key as a number
36
+ * @param key
37
+ */
38
+ number(key) {
39
+ for (const arg of this.m_args) {
40
+ if (arg.key === key) {
41
+ return parseInt(arg.value, 10);
42
+ }
43
+ }
44
+ return 0;
45
+ }
46
+ /**
47
+ * Retrieves the request key as a boolean
48
+ * @param key
49
+ */
50
+ boolean(key) {
51
+ for (const arg of this.m_args) {
52
+ if (arg.key === key) {
53
+ return arg.value;
54
+ }
55
+ }
56
+ return false;
57
+ }
58
+ /**
59
+ * Retrieves the requested key from a character code
60
+ * @param key
61
+ */
62
+ char(key) {
63
+ const num = this.number(key);
64
+ return (num !== 0) ? String.fromCharCode(num) : '';
65
+ }
66
+ /**
67
+ * Retrieves the value from the arguments that has no key, if it exists
68
+ */
69
+ nokey() {
70
+ for (const arg of this.m_args) {
71
+ if (arg.key !== 'result' && arg.value) {
72
+ return arg.key;
73
+ }
74
+ }
75
+ return '';
76
+ }
77
+ }
78
+ exports.default = ResponseArguments;
@@ -0,0 +1,51 @@
1
+ import ResponseArguments from './response_arguments';
2
+ /**
3
+ * The Current Context State
4
+ */
5
+ export declare enum ContextState {
6
+ INIT = 0,
7
+ WAITING = 2
8
+ }
9
+ /**
10
+ * The Current Channel State
11
+ */
12
+ export declare enum ChannelState {
13
+ DOWN_AVAILABLE = 0,
14
+ DOWN_RESERVED = 1,
15
+ OFF_HOOK = 2,
16
+ DIGITS_DIALED = 3,
17
+ RINGING = 4,
18
+ REMOTE_RINGING = 5,
19
+ UP = 6,
20
+ BUSY = 7
21
+ }
22
+ /**
23
+ * Represents the result of a Dial() attempt
24
+ */
25
+ export declare enum DialStatus {
26
+ ANSWER = 0,
27
+ BUSY = 1,
28
+ NOANSWER = 2,
29
+ CANCEL = 3,
30
+ CONGESTION = 4,
31
+ CHANUNAVAIL = 5,
32
+ DONTCALL = 6,
33
+ TORTURE = 7,
34
+ INVALIDARGS = 8
35
+ }
36
+ /**
37
+ * Represents the playback status
38
+ */
39
+ export declare enum PlaybackStatus {
40
+ SUCCESS = 0,
41
+ USER_STOPPED = 1,
42
+ REMOTE_STOPPED = 2,
43
+ ERROR = 3
44
+ }
45
+ /** @ignore */
46
+ export interface IResponse {
47
+ code: number;
48
+ result: number;
49
+ arguments: ResponseArguments;
50
+ }
51
+ export { ResponseArguments };
package/dist/types.js ADDED
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ // Copyright (c) 2016-2022 Brandon Lehmann
3
+ //
4
+ // Please see the included LICENSE file for more information.
5
+ var __importDefault = (this && this.__importDefault) || function (mod) {
6
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.ResponseArguments = exports.PlaybackStatus = exports.DialStatus = exports.ChannelState = exports.ContextState = void 0;
10
+ const response_arguments_1 = __importDefault(require("./response_arguments"));
11
+ exports.ResponseArguments = response_arguments_1.default;
12
+ /**
13
+ * The Current Context State
14
+ */
15
+ var ContextState;
16
+ (function (ContextState) {
17
+ ContextState[ContextState["INIT"] = 0] = "INIT";
18
+ ContextState[ContextState["WAITING"] = 2] = "WAITING";
19
+ })(ContextState = exports.ContextState || (exports.ContextState = {}));
20
+ /**
21
+ * The Current Channel State
22
+ */
23
+ var ChannelState;
24
+ (function (ChannelState) {
25
+ ChannelState[ChannelState["DOWN_AVAILABLE"] = 0] = "DOWN_AVAILABLE";
26
+ ChannelState[ChannelState["DOWN_RESERVED"] = 1] = "DOWN_RESERVED";
27
+ ChannelState[ChannelState["OFF_HOOK"] = 2] = "OFF_HOOK";
28
+ ChannelState[ChannelState["DIGITS_DIALED"] = 3] = "DIGITS_DIALED";
29
+ ChannelState[ChannelState["RINGING"] = 4] = "RINGING";
30
+ ChannelState[ChannelState["REMOTE_RINGING"] = 5] = "REMOTE_RINGING";
31
+ ChannelState[ChannelState["UP"] = 6] = "UP";
32
+ ChannelState[ChannelState["BUSY"] = 7] = "BUSY";
33
+ })(ChannelState = exports.ChannelState || (exports.ChannelState = {}));
34
+ /**
35
+ * Represents the result of a Dial() attempt
36
+ */
37
+ var DialStatus;
38
+ (function (DialStatus) {
39
+ DialStatus[DialStatus["ANSWER"] = 0] = "ANSWER";
40
+ DialStatus[DialStatus["BUSY"] = 1] = "BUSY";
41
+ DialStatus[DialStatus["NOANSWER"] = 2] = "NOANSWER";
42
+ DialStatus[DialStatus["CANCEL"] = 3] = "CANCEL";
43
+ DialStatus[DialStatus["CONGESTION"] = 4] = "CONGESTION";
44
+ DialStatus[DialStatus["CHANUNAVAIL"] = 5] = "CHANUNAVAIL";
45
+ DialStatus[DialStatus["DONTCALL"] = 6] = "DONTCALL";
46
+ DialStatus[DialStatus["TORTURE"] = 7] = "TORTURE";
47
+ DialStatus[DialStatus["INVALIDARGS"] = 8] = "INVALIDARGS";
48
+ })(DialStatus = exports.DialStatus || (exports.DialStatus = {}));
49
+ /**
50
+ * Represents the playback status
51
+ */
52
+ var PlaybackStatus;
53
+ (function (PlaybackStatus) {
54
+ PlaybackStatus[PlaybackStatus["SUCCESS"] = 0] = "SUCCESS";
55
+ PlaybackStatus[PlaybackStatus["USER_STOPPED"] = 1] = "USER_STOPPED";
56
+ PlaybackStatus[PlaybackStatus["REMOTE_STOPPED"] = 2] = "REMOTE_STOPPED";
57
+ PlaybackStatus[PlaybackStatus["ERROR"] = 3] = "ERROR";
58
+ })(PlaybackStatus = exports.PlaybackStatus || (exports.PlaybackStatus = {}));
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@gibme/asterisk-gateway-interface",
3
+ "version": "1.0.1",
4
+ "description": "Simple Asterisk Gateway Interface Helper",
5
+ "main": "dist/asterisk-gateway-interface.js",
6
+ "types": "dist/asterisk-gateway-interface.d.ts",
7
+ "files": [
8
+ "dist/*"
9
+ ],
10
+ "license": "MIT",
11
+ "scripts": {
12
+ "build": "./node_modules/.bin/tsc",
13
+ "test": "yarn style",
14
+ "style": "./node_modules/.bin/eslint src/**/*.ts",
15
+ "fix-style": "./node_modules/.bin/eslint --fix src/**/*.ts",
16
+ "fix:style": "yarn fix-style",
17
+ "prepublishOnly": "yarn build"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/gibme-npm/asterisk-gateway-interface.git"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/gibme-npm/asterisk-gateway-interface/issues"
25
+ },
26
+ "engines": {
27
+ "node": ">=16"
28
+ },
29
+ "engineStrict": true,
30
+ "author": {
31
+ "name": "Brandon Lehmann",
32
+ "email": "brandonlehmann@gmail.com"
33
+ },
34
+ "dependencies": {
35
+ "@gibme/timer": "^1.0.0",
36
+ "@types/uuid": "^8.3.4",
37
+ "dotenv": "^16.0.3",
38
+ "uuid": "^9.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^18.11.9",
42
+ "@typescript-eslint/eslint-plugin": "^5.42.0",
43
+ "@typescript-eslint/parser": "^5.42.0",
44
+ "eslint": "^8.26.0",
45
+ "eslint-config-standard": "^17.0.0",
46
+ "eslint-plugin-import": "^2.26.0",
47
+ "eslint-plugin-n": "^15.4.0",
48
+ "eslint-plugin-node": "^11.1.0",
49
+ "eslint-plugin-promise": "^6.1.1",
50
+ "ts-node": "^10.9.1",
51
+ "typescript": "^4.8.4"
52
+ }
53
+ }