Skip to content

Commit

Permalink
Add support for new locationOverride field (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbramblett authored Sep 10, 2024
1 parent ef7d6a9 commit 26245ae
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 14 deletions.
10 changes: 7 additions & 3 deletions packages/chat-core-aws-connect/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
## Testing Process

### Unit Testing

We use Jest as our framework for unit tests. Execute the unit tests with the following command:

```
npm run test
```

### Test Environments

The `chat-core-aws-connect` library is designed to be compatible with both CommonJS and ES6 import styles. Additionally, it should function properly in browser environments. To ensure this, we have set up a shared testing environment:

- **Browser ESM Test Site:** For more information, refer to the README.md file located in the `test-sites/test-browser-esm` directory.

## Build Process

Before initiating the build, run the linting process to identify and address any errors or warnings. Use the following command:

```
npm run lint
```

To build the library, execute:

```
npm run build
```
This will create the bundle in the `/dist` directory. This command will also generate documentation files and the `THIRD-PARTY-NOTICES` file.


This will create the bundle in the `/dist` directory. This command will also generate documentation files and the `THIRD-PARTY-NOTICES` file.

For guidelines on pull request and version publish process, visit Chat SDK wiki page.
For guidelines on pull request and version publish process, visit Chat SDK wiki page.
2 changes: 1 addition & 1 deletion packages/chat-core-aws-connect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const req = {
{
timestamp: "2023-05-17T19:21:21.915Z",
source: "USER",
text: "Could I get some assistance?"
text: "Could I get some assistance?",
},
],
};
Expand Down
10 changes: 7 additions & 3 deletions packages/chat-core/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
## Testing Process

### Unit Testing

We use Jest as our framework for unit tests. Execute the unit tests with the following command:

```
npm run test
```

### Test Environments

The `chat-core` library is designed to be compatible with both CommonJS and ES6 import styles. Additionally, it should function properly in both browser and Node.js environments. To ensure this, we have set up two distinct test environments:

- **Browser ESM Test Site:** For more information, refer to the README.md file located in the `test-sites/test-browser-esm` directory.
Expand All @@ -16,16 +19,17 @@ The `chat-core` library is designed to be compatible with both CommonJS and ES6
## Build Process

Before initiating the build, run the linting process to identify and address any errors or warnings. Use the following command:

```
npm run lint
```

To build the library, execute:

```
npm run build
```
This will create the bundle in the `/dist` directory. This command will also generate documentation files and the `THIRD-PARTY-NOTICES` file.


This will create the bundle in the `/dist` directory. This command will also generate documentation files and the `THIRD-PARTY-NOTICES` file.

For guidelines on pull request and version publish process, visit Chat SDK wiki page.
For guidelines on pull request and version publish process, visit Chat SDK wiki page.
21 changes: 21 additions & 0 deletions packages/chat-core/docs/chat-core.chatconfig.locationoverride.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/chat-core](./chat-core.md) &gt; [ChatConfig](./chat-core.chatconfig.md) &gt; [locationOverride](./chat-core.chatconfig.locationoverride.md)

## ChatConfig.locationOverride property

An optional location override to use instead of the user's provided location.

**Signature:**

```typescript
locationOverride?: {
latitude: number;
longitude: number;
};
```

## Remarks

If provided, Search steps will not attempt to infer the location from the request data and will use this latitude and longitude instead.

1 change: 1 addition & 0 deletions packages/chat-core/docs/chat-core.chatconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface ChatConfig
| [businessId?](./chat-core.chatconfig.businessid.md) | | number | _(Optional)_ ID of the account associated with this chat bot. |
| [endpoints?](./chat-core.chatconfig.endpoints.md) | | [Endpoints](./chat-core.endpoints.md) | _(Optional)_ Overrides for the URLs which are used when making requests to the Chat API. |
| [env?](./chat-core.chatconfig.env.md) | | [EnumOrLiteral](./chat-core.enumorliteral.md)<!-- -->&lt;[Environment](./chat-core.environment.md)<!-- -->&gt; | _(Optional)_ Defines the environment of the API domains. |
| [locationOverride?](./chat-core.chatconfig.locationoverride.md) | | { latitude: number; longitude: number; } | _(Optional)_ An optional location override to use instead of the user's provided location. |
| [region?](./chat-core.chatconfig.region.md) | | [EnumOrLiteral](./chat-core.enumorliteral.md)<!-- -->&lt;[Region](./chat-core.region.md)<!-- -->&gt; | _(Optional)_ The region to send the requests to. |
| [version?](./chat-core.chatconfig.version.md) | | string | _(Optional)_ The version of the chat bot configuration. |

4 changes: 4 additions & 0 deletions packages/chat-core/etc/chat-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export interface ChatConfig {
businessId?: number;
endpoints?: Endpoints;
env?: EnumOrLiteral<Environment>;
locationOverride?: {
latitude: number;
longitude: number;
};
region?: EnumOrLiteral<Region>;
version?: string;
}
Expand Down
1 change: 1 addition & 0 deletions packages/chat-core/src/infra/ChatCoreImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class ChatCoreImpl implements ChatCore {
...request,
version: this.chatConfig.version,
promptPackage: this.internalConfig.promptPackage,
locationOverride: this.chatConfig.locationOverride,
};
const rawResponse = await this.httpService.post(
this.endpoints.chat,
Expand Down
8 changes: 8 additions & 0 deletions packages/chat-core/src/models/ChatConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ export interface ChatConfig {
region?: EnumOrLiteral<Region>;
/** Overrides for the URLs which are used when making requests to the Chat API. */
endpoints?: Endpoints;
/**
* An optional location override to use instead of the user's provided location.
*
* @remarks
* If provided, Search steps will not attempt to infer the location from
* the request data and will use this latitude and longitude instead.
*/
locationOverride?: { latitude: number; longitude: number };
}
2 changes: 2 additions & 0 deletions packages/chat-core/src/models/endpoints/MessageRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ export interface ApiMessageRequest {
notes?: MessageNotes;
/** {@inheritDoc InternalConfig.promptPackage} */
promptPackage?: ChatPrompt;
/** {@inheritDoc ChatConfig.locationOverride} */
locationOverride?: { latitude: number; longitude: number };
}
5 changes: 1 addition & 4 deletions test-sites/test-browser-esm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
</style>
</head>
<body>
<input
id="messageInput"
type="text"
/>
<input id="messageInput" type="text" />
<button onclick="getNextMessage()">Chat</button>
<button onclick="streamNextMessage()">Chat (Stream)</button>
<button id="reset" onclick="resetSession()">Reset</button>
Expand Down
4 changes: 1 addition & 3 deletions test-sites/test-browser-esm/src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ window.resetSession = () => {
if (coreAws.getSession()) {
coreAws.resetSession();
}

msgs.innerHTML = "";
jsonRes.textContent = "";
convoHistory = [];
Expand Down Expand Up @@ -77,8 +77,6 @@ window.getNextMessage = async () => {
coreAws.emit("typing");
});



await coreAws.init(data);
}
}
Expand Down

0 comments on commit 26245ae

Please sign in to comment.