marc-recommend
Version:
Wrapper for the Flike Recommendation API.
219 lines (127 loc) • 6.62 kB
Markdown
@flike/recommend
More information about Flike can be found [here](https://goflike.app).
## Table of contents
### [Installation](#README.md#installation)
### [Quick Start](#README.md#quick-start)
### Classes
- [Recommender](README.md#class-recommender)
### Interfaces
- [Recommendation](README.md#interface-recommendation)
- [RecommendationsResponse](README.md#interface-recommendationsresponse)
# Installation
Install the [@flike/recommend](https://www.npmjs.com/package/@flike/recommend) package:
```
npm install @flike/recommend
```
# Quick Guide
1. Install the module as described in [Installation](#installation).
2. Import the module into your code
`import {Recommender} from '@flike/recommend'`
3. Instantiate the `Recommender` with your API key.
`const recommender = new Recommender(<your API key>);`
4. Call the corresponding methods whenever a user interacts with a content item.
- `start` when a user starts interacting with a content item.
- `like` when a user seems to like a content item. E.g. in the case of a video, call `like` when the user watched more than 80% of a video.
- `dislike` when a user seems to dislike a content item. E.g., in the case of a video, call `dislike` when they stop watching after watching less than 50% of it.
5. Retrieve recommendations for a user by calling the `recommend` method.
6. Filter and sort the recommendations if any constraints need to be considered.
7. Display/Use the recommendation in your application in whatever way applicable.
# Class: Recommender
Flike Recommender lets you easily log relevant user interactions with content items and recommend content items to users based on their interactions.
## Constructors
### constructor
• **new Recommender**(`api_key`, `server_url?`, `version?`)
#### Parameters
| Name | Type | Description |
| :------------ | :------- | :--------------------------------------------------------------- |
| `api_key` | `string` | Your API key. |
| `server_url?` | `string` | (only used for internal testing) |
| `version?` | `string` | Version of the API to use. Defaults to the most current version. |
## Methods
### dislike
▸ **dislike**(`user_id`, `item_id`): `Promise`<`boolean`\>
Registers a user-started item as 'disliked' by the user.
'Dislike' refers to any action indicating that a user dislikes the content item.
E.g., for a video, this could be a user only watching 5% of the video and not finishing it.
#### Parameters
| Name | Type | Description |
| :-------- | :------- | :----------------------------------------- |
| `user_id` | `string` | The unique identifier of the user. |
| `item_id` | `string` | The unique identifier of the content item. |
#### Returns
`Promise`<`boolean`\>
Resolves to true if successful. Otherwise, it will throw an exception.
---
### like
▸ **like**(`user_id`, `item_id`): `Promise`<`boolean`\>
Registers a user-started item as 'liked' by the user.
'Like' refers to any action indicating that a user likes the content item.
E.g. for a video, this could be a user watching more than 85% of the video.
#### Parameters
| Name | Type | Description |
| :-------- | :------- | :----------------------------------------- |
| `user_id` | `string` | The unique identifier of the user. |
| `item_id` | `string` | The unique identifier of the content item. |
#### Returns
`Promise`<`boolean`\>
Resolves to true if successful. Otherwise, it will throw an exception.
---
### recommend
▸ **recommend**(`user_id`, `num_items?`): `Promise`<[`RecommendationsResponse`](README.md#interface-recommendationsresponse)\>
Get an array of content items that a user is probable to consume/buy/subscribe/like or similar.
Recommendations are sorted by descending probability of a user 'liking' them.
#### Parameters
| Name | Type | Description |
| :----------- | :------- | :------------------------------------------------ |
| `user_id` | `string` | The unique identifier of the user. |
| `num_items?` | `number` | Number of content items that should be suggested. |
#### Returns
`Promise`<[`RecommendationsResponse`](README.md#interface-recommendationsresponse)\>
Resolves to a `RecommendationResponse` if successful. Otherwise, it will throw an exception.
---
### start
▸ **start**(`user_id`, `item_id`, `correlation_id?`): `Promise`<`boolean`\>
Registers a user starting to consume/interact with a content item.
#### Parameters
| Name | Type | Description |
| :---------------- | :------- | :--------------------------------------------------------------------------------------------------------------- |
| `user_id` | `string` | The unique identifier of the user. |
| `item_id` | `string` | The unique identifier of the content item. |
| `correlation_id?` | `string` | The unique identifier of a recommendation. Set this value to attribute a user's interaction to a recommendation. |
#### Returns
`Promise`<`boolean`\>
Resolves to true if successful. Otherwise, it will throw an exception.
---
### validate
▸ **validate**(): `Promise`<`boolean`\>
Validates the connectivity to the API.
#### Returns
`Promise`<`boolean`\>
Resolves to `true` if the connection is successful, `false` otherwise.




# Interface: Recommendation
Recommendation of a content item for a user.
## Table of contents
### Properties
- [item_id](README.md#item_id)
- [probability](README.md#probability)
## Properties
### item_id
• **item_id**: `string`
Unique identifier of the content item being recommended.
### probability
• **probability**: `number`
Probability of a user 'liking' the recommended item.
# Interface: RecommendationsResponse
## Table of contents
### Properties
- [correlation_id](README.md#correlation_id)
- [items](README.md#items)
## Properties
### correlation_id
• **correlation_id**: `string`
The unique identifier of this recommendation.
### items
• **items**: [`Recommendation`](README.md#interface-recommendation)[]
Recommendations for a user.