@fonoster/apiserver 0.9.50 → 0.9.52

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.
@@ -30,14 +30,16 @@ exports.createCall = createCall;
30
30
  */
31
31
  const common_1 = require("@fonoster/common");
32
32
  const logger_1 = require("@fonoster/logger");
33
+ const pb_util_1 = require("pb-util");
33
34
  const uuid_1 = require("uuid");
34
35
  const notFoundError_1 = require("../core/notFoundError");
35
36
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
36
37
  function createCall(prisma, publisher) {
37
38
  const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
38
39
  const { request } = call;
39
- const { from, to, appRef, timeout } = request;
40
+ const { from, to, appRef, timeout, metadata } = request;
40
41
  const ref = (0, uuid_1.v4)();
42
+ const effectiveMetadata = metadata ? pb_util_1.struct.decode(metadata) : {};
41
43
  logger.verbose("call to createCall", Object.assign(Object.assign({}, request), { ref }));
42
44
  const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(call);
43
45
  const app = yield prisma.application.findUnique({
@@ -52,7 +54,8 @@ function createCall(prisma, publisher) {
52
54
  to,
53
55
  appRef,
54
56
  accessKeyId,
55
- timeout: timeout || 60
57
+ timeout: timeout || 30,
58
+ metadata: effectiveMetadata
56
59
  });
57
60
  callback(null, { ref });
58
61
  });
@@ -55,7 +55,7 @@ function createCreateCallSubscriber(config) {
55
55
  if (err) {
56
56
  logger.error(err);
57
57
  }
58
- const { ref, from, to, appRef, accessKeyId, timeout } = msg.json();
58
+ const { ref, from, to, appRef, accessKeyId, timeout, metadata } = msg.json();
59
59
  logger.verbose("received a new call request", Object.assign({}, msg.json()));
60
60
  yield ariConn.channels.originateWithId({
61
61
  channelId: ref,
@@ -69,7 +69,8 @@ function createCreateCallSubscriber(config) {
69
69
  "PJSIP_HEADER(add,X-Is-Api-Originated-Type)": "true",
70
70
  CALL_DIRECTION: "peer-to-pstn",
71
71
  INGRESS_NUMBER: from,
72
- APP_REF: appRef
72
+ APP_REF: appRef,
73
+ METADATA: JSON.stringify(metadata)
73
74
  }
74
75
  });
75
76
  });
@@ -17,7 +17,7 @@
17
17
  * limitations under the License.
18
18
  */
19
19
  import { DialStatus, GrpcErrorMessage } from "@fonoster/common";
20
- import { CallDetailRecord, CallStatus, CallType } from "@fonoster/types";
20
+ import { CallDetailRecord, CallStatus, CallType, CreateCallRequest } from "@fonoster/types";
21
21
  type ListCallsRequest = {
22
22
  after?: string;
23
23
  before?: string;
@@ -35,12 +35,6 @@ type ListCallsResponse = {
35
35
  type GetCallRequest = {
36
36
  ref: string;
37
37
  };
38
- type CreateCallRequest = {
39
- from: string;
40
- to: string;
41
- appRef?: string;
42
- timeout?: number;
43
- };
44
38
  type CallPublisher = {
45
39
  publishCall: (event: CreateCallRequest & {
46
40
  ref: string;
@@ -41,7 +41,7 @@ const generateCallAccessToken = (0, identity_1.createGenerateCallAccessToken)(id
41
41
  function createCreateVoiceClient(createContainer, filesServer) {
42
42
  return function createVoiceClient(params) {
43
43
  return __awaiter(this, void 0, void 0, function* () {
44
- var _a, _b, _c, _d;
44
+ var _a, _b, _c, _d, _e;
45
45
  const { ari, event, channel } = params;
46
46
  const { id: sessionRef, caller } = event.channel;
47
47
  const { name: callerName, number: callerNumber } = caller;
@@ -52,7 +52,7 @@ function createCreateVoiceClient(createContainer, filesServer) {
52
52
  const ingressNumber = ((_c = (yield getChannelVar(types_1.ChannelVar.INGRESS_NUMBER))) === null || _c === void 0 ? void 0 : _c.value) || "";
53
53
  const { accessKeyId, endpoint, tts, stt } = yield createContainer(appRef);
54
54
  const sessionToken = yield generateCallAccessToken({ accessKeyId, appRef });
55
- const metadataStr = (_d = (yield getChannelVar(types_1.ChannelVar.METADATA))) === null || _d === void 0 ? void 0 : _d.value;
55
+ const metadataStr = (_e = (_d = (yield getChannelVar(types_1.ChannelVar.METADATA))) === null || _d === void 0 ? void 0 : _d.value) !== null && _e !== void 0 ? _e : "{}";
56
56
  const config = {
57
57
  appRef,
58
58
  sessionRef,
@@ -63,7 +63,7 @@ function createCreateVoiceClient(createContainer, filesServer) {
63
63
  ingressNumber,
64
64
  sessionToken,
65
65
  callDirection: (0, mapCallDirectionToEnum_1.mapCallDirectionToEnum)(callDirection),
66
- metadata: metadataStr ? JSON.parse(metadataStr) : {}
66
+ metadata: JSON.parse(metadataStr)
67
67
  };
68
68
  logger.verbose("creating voice client with config: ", {
69
69
  appRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/apiserver",
3
- "version": "0.9.50",
3
+ "version": "0.9.52",
4
4
  "description": "APIServer for Fonoster",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -21,13 +21,13 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@deepgram/sdk": "^3.5.1",
24
- "@fonoster/authz": "^0.9.50",
25
- "@fonoster/common": "^0.9.50",
26
- "@fonoster/identity": "^0.9.50",
27
- "@fonoster/logger": "^0.9.50",
28
- "@fonoster/sipnet": "^0.9.50",
29
- "@fonoster/streams": "^0.9.50",
30
- "@fonoster/types": "^0.9.50",
24
+ "@fonoster/authz": "^0.9.52",
25
+ "@fonoster/common": "^0.9.52",
26
+ "@fonoster/identity": "^0.9.52",
27
+ "@fonoster/logger": "^0.9.52",
28
+ "@fonoster/sipnet": "^0.9.52",
29
+ "@fonoster/streams": "^0.9.52",
30
+ "@fonoster/types": "^0.9.52",
31
31
  "@google-cloud/speech": "^6.6.0",
32
32
  "@google-cloud/text-to-speech": "^5.3.0",
33
33
  "@grpc/grpc-js": "~1.10.6",
@@ -73,5 +73,5 @@
73
73
  "@types/uuid": "^10.0.0",
74
74
  "@types/validator": "^13.12.0"
75
75
  },
76
- "gitHead": "8c88a1e1f0c849d428878253b94ea518c2c9b0f4"
76
+ "gitHead": "1926073ac39cb844501fca414a4f0311dcb0945c"
77
77
  }