Skip to content

Commit

Permalink
feat(*): added in-app message commands
Browse files Browse the repository at this point in the history
  • Loading branch information
MD4 committed Oct 4, 2024
1 parent 6fcf9f0 commit ddc05ea
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 0 deletions.
59 changes: 59 additions & 0 deletions packages/screeb-sdk-angular/docs/classes/Screeb.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
- [identityReset](Screeb.md#identityreset)
- [init](Screeb.md#init)
- [load](Screeb.md#load)
- [messageClose](Screeb.md#messageclose)
- [messageStart](Screeb.md#messagestart)
- [surveyClose](Screeb.md#surveyclose)
- [surveyStart](Screeb.md#surveystart)
- [targetingCheck](Screeb.md#targetingcheck)
Expand Down Expand Up @@ -422,6 +424,63 @@ this.screeb.load();

___

### messageClose

**messageClose**(): `Promise`\<`unknown`\>

Interrupts a running message.

#### Returns

`Promise`\<`unknown`\>

**`Example`**

```ts
this.screeb.messageClose();
```

___

### messageStart

**messageStart**(`messageId`, `hiddenFields`, `hooks?`, `language?`): `Promise`\<`unknown`\>

Starts a message by its ID.

#### Parameters

| Name | Type |
| :------ | :------ |
| `messageId` | `string` |
| `hiddenFields` | `PropertyRecord` |
| `hooks?` | `Hooks` |
| `language?` | `string` |

#### Returns

`Promise`\<`unknown`\>

**`Example`**

```ts
this.screeb.messageStart(
'<UUID>',
false,
{
color: "green",
article_id: 42
},
{
version: "1.0.0",
onMessageShowed: (payload) => console.log("Message showed", payload),
},
"en"
);
```

___

### surveyClose

**surveyClose**(): `Promise`\<`unknown`\>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,51 @@ export class Screeb {
);
}

/**
* Interrupts a running message.
*
* @example
* ```ts
* this.screeb.messageClose();
* ```
*/
public async messageClose() {
await this.ensureScreeb("messageClose");

return _Screeb.messageClose();
}

/**
* Starts a message by its ID.
*
* @example
* ```ts
* this.screeb.messageStart(
* '<UUID>',
* false,
* {
* color: "green",
* article_id: 42
* },
* {
* version: "1.0.0",
* onMessageShowed: (payload) => console.log("Message showed", payload),
* },
* "en"
* );
* ```
*/
public async messageStart(
messageId: string,
hiddenFields: _Screeb.PropertyRecord,
hooks?: _Screeb.Hooks,
language?: string
) {
await this.ensureScreeb("messageStart");

return _Screeb.messageStart(messageId, hiddenFields, hooks, language);
}

/**
* Forces a targeting check.
*
Expand Down
63 changes: 63 additions & 0 deletions packages/screeb-sdk-browser/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
- [init](README.md#init)
- [isLoaded](README.md#isloaded)
- [load](README.md#load)
- [messageClose](README.md#messageclose)
- [messageStart](README.md#messagestart)
- [surveyClose](README.md#surveyclose)
- [surveyStart](README.md#surveystart)
- [targetingCheck](README.md#targetingcheck)
Expand Down Expand Up @@ -793,6 +795,67 @@ Screeb.load();

___

### messageClose

**messageClose**(): `void` \| `Promise`\<`unknown`\>

Interrupts a running message.

#### Returns

`void` \| `Promise`\<`unknown`\>

**`Example`**

```ts
import * as Screeb from "@screeb/sdk-browser";

Screeb.messageClose();
```

___

### messageStart

**messageStart**(`messageId`, `hiddenFields?`, `hooks?`, `language?`): `void` \| `Promise`\<`unknown`\>

Starts a message by its ID.

#### Parameters

| Name | Type |
| :------ | :------ |
| `messageId` | `string` |
| `hiddenFields` | [`PropertyRecord`](README.md#propertyrecord) |
| `hooks?` | [`Hooks`](README.md#hooks) |
| `language?` | `string` |

#### Returns

`void` \| `Promise`\<`unknown`\>

**`Example`**

```ts
import * as Screeb from "@screeb/sdk-browser";

Screeb.messageStart(
'<UUID>',
false,
{
color: "green",
article_id: 42
},
{
version: "1.0.0",
onMessageShowed: (payload) => console.log("Message showed", payload),
},
"en"
);
```

___

### surveyClose

**surveyClose**(): `void` \| `Promise`\<`unknown`\>
Expand Down
46 changes: 46 additions & 0 deletions packages/screeb-sdk-browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,52 @@ export const surveyStart = (
hooks: hooks,
});

/**
* Interrupts a running message.
*
* @example
* ```ts
* import * as Screeb from "@screeb/sdk-browser";
*
* Screeb.messageClose();
* ```
*/
export const messageClose = () => callScreebCommand("message.close");

/**
* Starts a message by its ID.
*
* @example
* ```ts
* import * as Screeb from "@screeb/sdk-browser";
*
* Screeb.messageStart(
* '<UUID>',
* false,
* {
* color: "green",
* article_id: 42
* },
* {
* version: "1.0.0",
* onMessageShowed: (payload) => console.log("Message showed", payload),
* },
* "en"
* );
* ```
*/
export const messageStart = (
messageId: string,
hiddenFields: PropertyRecord = {},
hooks?: Hooks,
language?: string,
) =>
callScreebCommand("message.start", messageId, {
language: language,
hidden_fields: hiddenFields,
hooks: hooks,
});

/**
* Forces a targeting check.
*
Expand Down
66 changes: 66 additions & 0 deletions packages/screeb-sdk-react/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
- [IdentityResetFunction](README.md#identityresetfunction)
- [InitFunction](README.md#initfunction)
- [LoadFunction](README.md#loadfunction)
- [MessageCloseFunction](README.md#messageclosefunction)
- [MessageStartFunction](README.md#messagestartfunction)
- [ScreebContextValues](README.md#screebcontextvalues)
- [ScreebProps](README.md#screebprops)
- [ScreebProviderProps](README.md#screebproviderprops)
Expand Down Expand Up @@ -437,6 +439,70 @@ load();

___

### MessageCloseFunction

Ƭ **MessageCloseFunction**: () => `Promise`\<`unknown`\>

Interrupts a running message.

**`Example`**

```ts
const { messageClose } = useScreeb();

messageClose();
```

#### Type declaration

▸ (): `Promise`\<`unknown`\>

##### Returns

`Promise`\<`unknown`\>

___

### MessageStartFunction

Ƭ **MessageStartFunction**: (`messageId`: `string`, `hiddenFields`: `PropertyRecord`, `hooks?`: `Hooks`, `language?`: `string`) => `Promise`\<`unknown`\>

Starts a message by its ID.

**`Example`**

```ts
const { messageStart } = useScreeb();

messageStart(
'<UUID>',
false,
{
color: "green",
article_id: 42
}
);
```

#### Type declaration

▸ (`messageId`, `hiddenFields`, `hooks?`, `language?`): `Promise`\<`unknown`\>

##### Parameters

| Name | Type |
| :------ | :------ |
| `messageId` | `string` |
| `hiddenFields` | `PropertyRecord` |
| `hooks?` | `Hooks` |
| `language?` | `string` |

##### Returns

`Promise`\<`unknown`\>

___

### ScreebContextValues

Ƭ **ScreebContextValues**: `Object`
Expand Down
22 changes: 22 additions & 0 deletions packages/screeb-sdk-react/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,24 @@ export const ScreebProvider: React.FC<
[],
);

const messageClose = React.useCallback(
async () => await ensureScreeb("messageClose", () => Screeb.messageClose()),
[],
);

const messageStart = React.useCallback(
async (
messageId: string,
hiddenFields: Screeb.PropertyRecord,
hooks?: Screeb.Hooks,
language?: string,
) =>
await ensureScreeb("messageStart", () =>
Screeb.messageStart(messageId, hiddenFields, hooks, language),
),
[],
);

const targetingCheck = React.useCallback(
async () =>
await ensureScreeb("targetingCheck", () => Screeb.targetingCheck()),
Expand Down Expand Up @@ -241,6 +259,8 @@ export const ScreebProvider: React.FC<
load,
surveyClose,
surveyStart,
messageClose,
messageStart,
targetingCheck,
targetingDebug,
}),
Expand All @@ -258,6 +278,8 @@ export const ScreebProvider: React.FC<
load,
surveyClose,
surveyStart,
messageClose,
messageStart,
targetingCheck,
targetingDebug,
],
Expand Down
Loading

0 comments on commit ddc05ea

Please sign in to comment.