@snipet/angular-widget 0.2.1 → 0.2.2
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 +66 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @snipet/angular-widget
|
|
2
|
+
|
|
3
|
+
Angular bindings for the [Snipet chat widget](https://github.com/usesnipet/snipet/tree/main/apps/widget). Angular 19+.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @snipet/angular-widget
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
Provide the widget when the app starts; it mounts in the page corner.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// app.config.ts
|
|
15
|
+
import { provideSnipet } from "@snipet/angular-widget";
|
|
16
|
+
|
|
17
|
+
export const appConfig: ApplicationConfig = {
|
|
18
|
+
providers: [
|
|
19
|
+
provideSnipet({
|
|
20
|
+
apiUrl: "https://snipet.example.com",
|
|
21
|
+
appId: "<your app id>",
|
|
22
|
+
agentId: "<your agent id>",
|
|
23
|
+
theme: "auto",
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The config takes the widget's [options](https://github.com/usesnipet/snipet/tree/main/apps/widget#options). An optional second argument
|
|
30
|
+
overrides where the widget script loads from (default: unpkg, same version as this package).
|
|
31
|
+
|
|
32
|
+
Control it anywhere with the `SNIPET` token:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { DestroyRef, inject } from "@angular/core";
|
|
36
|
+
import { SNIPET } from "@snipet/angular-widget";
|
|
37
|
+
|
|
38
|
+
export class HelpButtonComponent {
|
|
39
|
+
private snipet = inject(SNIPET);
|
|
40
|
+
|
|
41
|
+
constructor() {
|
|
42
|
+
const off = this.snipet.on("message", (message) => console.log(message.role, message.text));
|
|
43
|
+
inject(DestroyRef).onDestroy(off);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
open() {
|
|
47
|
+
this.snipet.open();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`SNIPET` has `open`, `close`, `toggle`, `enable`, `disable`, `configure`, `setToken` and
|
|
53
|
+
`on` (see [events](https://github.com/usesnipet/snipet/tree/main/apps/widget#events)). Calls made before the script loads are queued.
|
|
54
|
+
|
|
55
|
+
### Signed-in users
|
|
56
|
+
|
|
57
|
+
Pass the token once you have it:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
this.snipet.setToken(token); // null signs the user out
|
|
61
|
+
this.snipet.configure({ getToken: () => firstValueFrom(this.api.snipetToken()) });
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Issue tokens from your backend; see [signing in end users](https://github.com/usesnipet/snipet/tree/main/apps/widget#signing-in-end-users).
|
|
65
|
+
|
|
66
|
+
SSR-safe: on the server the widget doesn't mount and `SNIPET` calls do nothing.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snipet/angular-widget",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Angular bindings for the Snipet chat widget.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@snipet/widget": "0.2.
|
|
25
|
+
"@snipet/widget": "0.2.2"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@angular/common": ">=19",
|