@fonoster/apiserver 0.7.15 → 0.7.18

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.
@@ -67,6 +67,7 @@ function createCreateCallSubscriber(config) {
67
67
  "PJSIP_HEADER(add,X-Dod-Number)": from,
68
68
  "PJSIP_HEADER(add,X-Access-Key-Id)": accessKeyId,
69
69
  "PJSIP_HEADER(add,X-Is-Api-Originated-Type)": "true",
70
+ CALL_DIRECTION: "peer-to-pstn",
70
71
  INGRESS_NUMBER: from,
71
72
  APP_REF: appRef
72
73
  }
@@ -14,12 +14,15 @@ const withErrorHandling_1 = require("./utils/withErrorHandling");
14
14
  function hangupHandler(ari, voiceClient) {
15
15
  return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
16
16
  const { sessionRef } = request;
17
- yield ari.channels.hangup({ channelId: sessionRef });
18
- voiceClient.sendResponse({
19
- hangupResponse: {
20
- sessionRef
21
- }
22
- });
23
- voiceClient.close();
17
+ // Give some time for the last sound to play
18
+ setTimeout(() => {
19
+ ari.channels.hangup({ channelId: sessionRef });
20
+ voiceClient.sendResponse({
21
+ hangupResponse: {
22
+ sessionRef
23
+ }
24
+ });
25
+ voiceClient.close();
26
+ }, 2000);
24
27
  }));
25
28
  }
@@ -36,12 +36,10 @@ function handleStasisStart(params) {
36
36
  return (_, channel) => __awaiter(this, void 0, void 0, function* () {
37
37
  try {
38
38
  yield bridge.addChannel({ channel: dialed.id });
39
- if (recordDirection === common_1.DialRecordDirection.IN ||
40
- recordDirection === common_1.DialRecordDirection.BOTH) {
39
+ if ([common_1.DialRecordDirection.IN, common_1.DialRecordDirection.BOTH].includes(recordDirection)) {
41
40
  (0, recordChannel_1.recordChannel)(ari, common_1.DialRecordDirection.IN, channel.id);
42
41
  }
43
- if (recordDirection === common_1.DialRecordDirection.OUT ||
44
- recordDirection === common_1.DialRecordDirection.BOTH) {
42
+ if ([common_1.DialRecordDirection.OUT, common_1.DialRecordDirection.BOTH].includes(recordDirection)) {
45
43
  (0, recordChannel_1.recordChannel)(ari, common_1.DialRecordDirection.OUT, dialed.id);
46
44
  }
47
45
  }
@@ -31,15 +31,16 @@ exports.recordChannel = recordChannel;
31
31
  const common_1 = require("@fonoster/common");
32
32
  function recordChannel(ari, direction, sessionRef) {
33
33
  return __awaiter(this, void 0, void 0, function* () {
34
+ const spy = direction.toLowerCase();
34
35
  const channel = yield ari.channels.snoopChannel({
35
36
  app: common_1.STASIS_APP_NAME,
36
37
  channelId: sessionRef,
37
- spy: direction
38
+ spy
38
39
  });
39
40
  return ari.channels.record({
40
41
  channelId: channel.id,
41
42
  format: common_1.RecordFormat.WAV,
42
- name: `${sessionRef}_${direction}`
43
+ name: `${sessionRef}_${spy}`
43
44
  });
44
45
  });
45
46
  }
@@ -34,22 +34,24 @@ const makeGetChannelVar_1 = require("./makeGetChannelVar");
34
34
  const types_1 = require("./types");
35
35
  const VoiceClientImpl_1 = require("./VoiceClientImpl");
36
36
  const identityConfig_1 = require("../core/identityConfig");
37
+ const mapCallDirectionToEnum_1 = require("../events/mapCallDirectionToEnum");
37
38
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
38
39
  const createToken = (0, identity_1.createCallAccessToken)(identityConfig_1.identityConfig);
39
40
  // Note: By the time the call arrives here the owner of the app MUST be authenticated
40
41
  function makeCreateVoiceClient(createContainer) {
41
42
  return (params) => __awaiter(this, void 0, void 0, function* () {
42
- var _a, _b, _c;
43
+ var _a, _b, _c, _d;
43
44
  const { ari, event, channel } = params;
44
45
  const { id: sessionRef, caller } = event.channel;
45
46
  const { name: callerName, number: callerNumber } = caller;
46
47
  const getChannelVar = (0, makeGetChannelVar_1.makeGetChannelVarWithoutThrow)(channel);
47
48
  // Variables set by Asterisk's dialplan
48
- const appRef = (_a = (yield getChannelVar(types_1.ChannelVar.APP_REF))) === null || _a === void 0 ? void 0 : _a.value;
49
- const ingressNumber = ((_b = (yield getChannelVar(types_1.ChannelVar.INGRESS_NUMBER))) === null || _b === void 0 ? void 0 : _b.value) || "";
49
+ const callDirection = (_a = (yield getChannelVar(types_1.ChannelVar.CALL_DIRECTION))) === null || _a === void 0 ? void 0 : _a.value;
50
+ const appRef = (_b = (yield getChannelVar(types_1.ChannelVar.APP_REF))) === null || _b === void 0 ? void 0 : _b.value;
51
+ const ingressNumber = ((_c = (yield getChannelVar(types_1.ChannelVar.INGRESS_NUMBER))) === null || _c === void 0 ? void 0 : _c.value) || "";
50
52
  const { accessKeyId, endpoint, tts, stt } = yield createContainer(appRef);
51
53
  const sessionToken = yield createToken({ accessKeyId, appRef });
52
- const metadataStr = (_c = (yield getChannelVar(types_1.ChannelVar.METADATA))) === null || _c === void 0 ? void 0 : _c.value;
54
+ const metadataStr = (_d = (yield getChannelVar(types_1.ChannelVar.METADATA))) === null || _d === void 0 ? void 0 : _d.value;
53
55
  const config = {
54
56
  appRef,
55
57
  sessionRef,
@@ -59,6 +61,7 @@ function makeCreateVoiceClient(createContainer) {
59
61
  callerNumber,
60
62
  ingressNumber,
61
63
  sessionToken,
64
+ callDirection: (0, mapCallDirectionToEnum_1.mapCallDirectionToEnum)(callDirection),
62
65
  metadata: metadataStr ? JSON.parse(metadataStr) : {}
63
66
  };
64
67
  logger.verbose("creating voice client with config: ", {
@@ -12,11 +12,11 @@ declare enum AriEvent {
12
12
  DIAL = "Dial"
13
13
  }
14
14
  declare enum ChannelVar {
15
+ CALL_DIRECTION = "CALL_DIRECTION",
15
16
  INGRESS_NUMBER = "INGRESS_NUMBER",
16
17
  APP_REF = "APP_REF",
17
18
  APP_ENDPOINT = "APP_ENDPOINT",
18
19
  METADATA = "METADATA",
19
- CURRENT_BRIDGE = "CURRENT_BRIDGE",
20
20
  FROM_EXTERNAL_MEDIA = "FROM_EXTERNAL_MEDIA"
21
21
  }
22
22
  export { AriEvent, ChannelVar };
@@ -35,10 +35,10 @@ var AriEvent;
35
35
  })(AriEvent || (exports.AriEvent = AriEvent = {}));
36
36
  var ChannelVar;
37
37
  (function (ChannelVar) {
38
+ ChannelVar["CALL_DIRECTION"] = "CALL_DIRECTION";
38
39
  ChannelVar["INGRESS_NUMBER"] = "INGRESS_NUMBER";
39
40
  ChannelVar["APP_REF"] = "APP_REF";
40
41
  ChannelVar["APP_ENDPOINT"] = "APP_ENDPOINT";
41
42
  ChannelVar["METADATA"] = "METADATA";
42
- ChannelVar["CURRENT_BRIDGE"] = "CURRENT_BRIDGE";
43
43
  ChannelVar["FROM_EXTERNAL_MEDIA"] = "FROM_EXTERNAL_MEDIA";
44
44
  })(ChannelVar || (exports.ChannelVar = ChannelVar = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/apiserver",
3
- "version": "0.7.15",
3
+ "version": "0.7.18",
4
4
  "description": "APIServer for Fonoster",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -21,12 +21,12 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@deepgram/sdk": "^3.5.1",
24
- "@fonoster/common": "^0.7.15",
25
- "@fonoster/identity": "^0.7.15",
26
- "@fonoster/logger": "^0.7.15",
27
- "@fonoster/sipnet": "^0.7.15",
28
- "@fonoster/streams": "^0.7.15",
29
- "@fonoster/types": "^0.7.15",
24
+ "@fonoster/common": "^0.7.18",
25
+ "@fonoster/identity": "^0.7.18",
26
+ "@fonoster/logger": "^0.7.18",
27
+ "@fonoster/sipnet": "^0.7.18",
28
+ "@fonoster/streams": "^0.7.18",
29
+ "@fonoster/types": "^0.7.18",
30
30
  "@google-cloud/speech": "^6.6.0",
31
31
  "@google-cloud/text-to-speech": "^5.3.0",
32
32
  "@grpc/grpc-js": "~1.10.6",
@@ -72,5 +72,5 @@
72
72
  "@types/uuid": "^9.0.8",
73
73
  "@types/validator": "^13.12.0"
74
74
  },
75
- "gitHead": "13997c49e69d79aa1a58cd0de1120984e3b8b6f1"
75
+ "gitHead": "4150dcb8086de182d0650df0c6d990ee76658058"
76
76
  }