phonic 0.25.4 → 0.26.0

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.
package/README.md CHANGED
@@ -9,6 +9,7 @@ Node.js library for the Phonic API.
9
9
  - [Get agent](#get-agent)
10
10
  - [Create agent](#create-agent)
11
11
  - [Update agent](#update-agent)
12
+ - [Upsert agent](#upsert-agent)
12
13
  - [Delete agent](#delete-agent)
13
14
  - [Tools](#tools)
14
15
  - [List tools](#list-tools)
@@ -133,6 +134,43 @@ const updateAgentResult = await phonic.agents.update("chris", {
133
134
  });
134
135
  ```
135
136
 
137
+ ### Upsert agent
138
+
139
+ ```ts
140
+ const upsertAgentResult = await phonic.agents.upsert({
141
+ name: "chris",
142
+
143
+ // Optional fields
144
+ project: "main",
145
+ phoneNumber: "assign-automatically", // or null
146
+ timezone: "Australia/Melbourne",
147
+ voiceId: "sarah",
148
+ audioFormat: "mulaw_8000", // Must be "mulaw_8000" when `phoneNumber` is "assign-automatically"
149
+ welcomeMessage: "Hello, how can I help you?",
150
+ systemPrompt: "You are an expert in {{subject}}. Be kind to {{user_name}}.",
151
+ templateVariables: {
152
+ subject: {
153
+ defaultValue: "Maths"
154
+ },
155
+ user_name: {
156
+ defaultValue: null
157
+ }
158
+ },
159
+ tools: ["keypad_input", "natural_conversation_ending", "my-custom-tool"],
160
+ noInputPokeSec: 30,
161
+ noInputPokeText: "Hey, are you with me?",
162
+ noInputEndConversationSec: 150,
163
+ boostedKeywords: ["Salamanca Market", "Bonorong Wildlife Sanctuary"],
164
+ configurationEndpoint: {
165
+ url: "https://myapp.com/webhooks/phonic-config",
166
+ headers: {
167
+ Authorization: "Bearer 123"
168
+ },
169
+ timeoutMs: 7000
170
+ }
171
+ });
172
+ ```
173
+
136
174
  ### Delete agent
137
175
 
138
176
  ```ts
package/dist/index.d.mts CHANGED
@@ -16,6 +16,10 @@ type FetchOptions = {
16
16
  method: "PATCH";
17
17
  headers?: Record<string, string>;
18
18
  body: string;
19
+ } | {
20
+ method: "PUT";
21
+ headers?: Record<string, string>;
22
+ body: string;
19
23
  } | {
20
24
  method: "DELETE";
21
25
  headers?: Record<string, string>;
@@ -239,6 +243,26 @@ type UpdateAgentParams = UpdateAgentWithPhoneNumberParams | UpdateAgentWithoutPh
239
243
  type UpdateAgentSuccessResponse = {
240
244
  success: true;
241
245
  };
246
+ interface UpsertAgentBaseParams extends AgentOptionalParams {
247
+ name: string;
248
+ }
249
+ interface UpsertAgentWithPhoneNumberParams extends UpsertAgentBaseParams, AgentPhoneNumberParams {
250
+ }
251
+ interface UpsertAgentWithoutPhoneNumberParams extends UpsertAgentBaseParams, AgentNoPhoneNumberParams {
252
+ }
253
+ type UpsertAgentParams = UpsertAgentWithPhoneNumberParams | UpsertAgentWithoutPhoneNumberParams;
254
+ interface UpsertAgentSuccessResponseBase {
255
+ agent: Agent;
256
+ }
257
+ interface UpsertAgentInsertedSuccessResponse extends UpsertAgentSuccessResponseBase {
258
+ inserted: true;
259
+ updated: false;
260
+ }
261
+ interface UpsertAgentUpdatedSuccessResponse extends UpsertAgentSuccessResponseBase {
262
+ inserted: false;
263
+ updated: true;
264
+ }
265
+ type UpsertAgentSuccessResponse = UpsertAgentInsertedSuccessResponse | UpsertAgentUpdatedSuccessResponse;
242
266
  type DeleteAgentParams = {
243
267
  project?: string;
244
268
  };
@@ -256,6 +280,7 @@ declare class Agents {
256
280
  get(name: string, params?: GetAgentParams): DataOrError<GetAgentSuccessResponse>;
257
281
  create(params: CreateAgentParams): DataOrError<CreateAgentSuccessResponse>;
258
282
  update(name: string, params: UpdateAgentParams): DataOrError<UpdateAgentSuccessResponse>;
283
+ upsert(params: UpsertAgentParams): DataOrError<UpsertAgentSuccessResponse>;
259
284
  delete(name: string, params?: DeleteAgentParams): DataOrError<DeleteAgentSuccessResponse>;
260
285
  }
261
286
 
@@ -501,6 +526,17 @@ declare class Phonic {
501
526
  data: T;
502
527
  error: null;
503
528
  }>;
529
+ put<T>(path: string, body: Record<string, unknown>, headers?: Record<string, string>): Promise<{
530
+ data: null;
531
+ error: {
532
+ message: string;
533
+ code?: string;
534
+ param_errors?: Record<string, string>;
535
+ };
536
+ } | {
537
+ data: T;
538
+ error: null;
539
+ }>;
504
540
  delete<T>(path: string, headers?: Record<string, string>): Promise<{
505
541
  data: null;
506
542
  error: {
package/dist/index.d.ts CHANGED
@@ -16,6 +16,10 @@ type FetchOptions = {
16
16
  method: "PATCH";
17
17
  headers?: Record<string, string>;
18
18
  body: string;
19
+ } | {
20
+ method: "PUT";
21
+ headers?: Record<string, string>;
22
+ body: string;
19
23
  } | {
20
24
  method: "DELETE";
21
25
  headers?: Record<string, string>;
@@ -239,6 +243,26 @@ type UpdateAgentParams = UpdateAgentWithPhoneNumberParams | UpdateAgentWithoutPh
239
243
  type UpdateAgentSuccessResponse = {
240
244
  success: true;
241
245
  };
246
+ interface UpsertAgentBaseParams extends AgentOptionalParams {
247
+ name: string;
248
+ }
249
+ interface UpsertAgentWithPhoneNumberParams extends UpsertAgentBaseParams, AgentPhoneNumberParams {
250
+ }
251
+ interface UpsertAgentWithoutPhoneNumberParams extends UpsertAgentBaseParams, AgentNoPhoneNumberParams {
252
+ }
253
+ type UpsertAgentParams = UpsertAgentWithPhoneNumberParams | UpsertAgentWithoutPhoneNumberParams;
254
+ interface UpsertAgentSuccessResponseBase {
255
+ agent: Agent;
256
+ }
257
+ interface UpsertAgentInsertedSuccessResponse extends UpsertAgentSuccessResponseBase {
258
+ inserted: true;
259
+ updated: false;
260
+ }
261
+ interface UpsertAgentUpdatedSuccessResponse extends UpsertAgentSuccessResponseBase {
262
+ inserted: false;
263
+ updated: true;
264
+ }
265
+ type UpsertAgentSuccessResponse = UpsertAgentInsertedSuccessResponse | UpsertAgentUpdatedSuccessResponse;
242
266
  type DeleteAgentParams = {
243
267
  project?: string;
244
268
  };
@@ -256,6 +280,7 @@ declare class Agents {
256
280
  get(name: string, params?: GetAgentParams): DataOrError<GetAgentSuccessResponse>;
257
281
  create(params: CreateAgentParams): DataOrError<CreateAgentSuccessResponse>;
258
282
  update(name: string, params: UpdateAgentParams): DataOrError<UpdateAgentSuccessResponse>;
283
+ upsert(params: UpsertAgentParams): DataOrError<UpsertAgentSuccessResponse>;
259
284
  delete(name: string, params?: DeleteAgentParams): DataOrError<DeleteAgentSuccessResponse>;
260
285
  }
261
286
 
@@ -501,6 +526,17 @@ declare class Phonic {
501
526
  data: T;
502
527
  error: null;
503
528
  }>;
529
+ put<T>(path: string, body: Record<string, unknown>, headers?: Record<string, string>): Promise<{
530
+ data: null;
531
+ error: {
532
+ message: string;
533
+ code?: string;
534
+ param_errors?: Record<string, string>;
535
+ };
536
+ } | {
537
+ data: T;
538
+ error: null;
539
+ }>;
504
540
  delete<T>(path: string, headers?: Record<string, string>): Promise<{
505
541
  data: null;
506
542
  error: {
package/dist/index.js CHANGED
@@ -35,7 +35,7 @@ __export(index_exports, {
35
35
  module.exports = __toCommonJS(index_exports);
36
36
 
37
37
  // package.json
38
- var version = "0.25.4";
38
+ var version = "0.26.0";
39
39
 
40
40
  // src/agents/index.ts
41
41
  var Agents = class {
@@ -136,6 +136,32 @@ var Agents = class {
136
136
  );
137
137
  return response;
138
138
  }
139
+ async upsert(params) {
140
+ const response = await this.phonic.put(
141
+ `/agents/upsert?${this.getQueryString(params)}`,
142
+ {
143
+ name: params.name,
144
+ phone_number: params.phoneNumber,
145
+ timezone: params.timezone,
146
+ audio_format: params.phoneNumber === "assign-automatically" ? "mulaw_8000" : params.audioFormat,
147
+ voice_id: params.voiceId,
148
+ welcome_message: params.welcomeMessage,
149
+ system_prompt: params.systemPrompt,
150
+ template_variables: this.getTemplateVariablesForBody(
151
+ params.templateVariables
152
+ ),
153
+ tools: params.tools,
154
+ no_input_poke_sec: params.noInputPokeSec,
155
+ no_input_poke_text: params.noInputPokeText,
156
+ no_input_end_conversation_sec: params.noInputEndConversationSec,
157
+ boosted_keywords: params.boostedKeywords,
158
+ configuration_endpoint: this.getConfigurationEndpointForBody(
159
+ params.configurationEndpoint
160
+ )
161
+ }
162
+ );
163
+ return response;
164
+ }
139
165
  async delete(name, params) {
140
166
  const response = await this.phonic.delete(
141
167
  `/agents/${name}?${this.getQueryString(params)}`
@@ -525,6 +551,13 @@ var Phonic = class {
525
551
  headers
526
552
  });
527
553
  }
554
+ async put(path, body, headers) {
555
+ return this.fetchRequest(path, {
556
+ method: "PUT",
557
+ body: JSON.stringify(body),
558
+ headers
559
+ });
560
+ }
528
561
  async delete(path, headers) {
529
562
  return this.fetchRequest(path, {
530
563
  method: "DELETE",
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.25.4";
2
+ var version = "0.26.0";
3
3
 
4
4
  // src/agents/index.ts
5
5
  var Agents = class {
@@ -100,6 +100,32 @@ var Agents = class {
100
100
  );
101
101
  return response;
102
102
  }
103
+ async upsert(params) {
104
+ const response = await this.phonic.put(
105
+ `/agents/upsert?${this.getQueryString(params)}`,
106
+ {
107
+ name: params.name,
108
+ phone_number: params.phoneNumber,
109
+ timezone: params.timezone,
110
+ audio_format: params.phoneNumber === "assign-automatically" ? "mulaw_8000" : params.audioFormat,
111
+ voice_id: params.voiceId,
112
+ welcome_message: params.welcomeMessage,
113
+ system_prompt: params.systemPrompt,
114
+ template_variables: this.getTemplateVariablesForBody(
115
+ params.templateVariables
116
+ ),
117
+ tools: params.tools,
118
+ no_input_poke_sec: params.noInputPokeSec,
119
+ no_input_poke_text: params.noInputPokeText,
120
+ no_input_end_conversation_sec: params.noInputEndConversationSec,
121
+ boosted_keywords: params.boostedKeywords,
122
+ configuration_endpoint: this.getConfigurationEndpointForBody(
123
+ params.configurationEndpoint
124
+ )
125
+ }
126
+ );
127
+ return response;
128
+ }
103
129
  async delete(name, params) {
104
130
  const response = await this.phonic.delete(
105
131
  `/agents/${name}?${this.getQueryString(params)}`
@@ -489,6 +515,13 @@ var Phonic = class {
489
515
  headers
490
516
  });
491
517
  }
518
+ async put(path, body, headers) {
519
+ return this.fetchRequest(path, {
520
+ method: "PUT",
521
+ body: JSON.stringify(body),
522
+ headers
523
+ });
524
+ }
492
525
  async delete(path, headers) {
493
526
  return this.fetchRequest(path, {
494
527
  method: "DELETE",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phonic",
3
- "version": "0.25.4",
3
+ "version": "0.26.0",
4
4
  "description": "Phonic Node.js SDK",
5
5
  "scripts": {
6
6
  "build": "tsup",