marc-recommend
Version:
Wrapper for the Flike Recommendation API.
82 lines (81 loc) • 3.5 kB
TypeScript
import { AxiosInstance } from "axios";
/**
* Recommendation of a content item for a user.
*/
export interface Recommendation {
/** Unique identifier of the content item being recommended. */
item_id: string;
/** Probability of a user 'liking' the recommended item. */
probability: number;
}
export interface RecommendationsResponse {
/** Recommendations for a user. */
items: Recommendation[];
/** The unique identifier of this recommendation. */
correlation_id: string;
}
/**
* Flike Recommender lets you easily log relevant user interactions with content items and recommend content items to users based on their interactions.
*/
export declare class Recommender {
/** @internal */
server_url: string;
/** @internal */
version: string;
/** @internal */
api_key: string;
/** @internal */
axiosInstance: AxiosInstance;
/**
*
*
* @param api_key Your API key.
* @param server_url (only used for internal testing)
* @param version Version of the API to use. Defaults to the most current version.
*/
constructor(api_key: string, server_url?: string, version?: string);
/**
* Validates the connectivity to the API.
*
* @returns Resolves to `true` if the connection is successful, `false` otherwise.
*/
validate(): Promise<boolean>;
/**
* Registers a user starting to consume/interact with a content item.
*
* @param user_id The unique identifier of the user.
* @param item_id The unique identifier of the content item.
* @param correlation_id The unique identifier of a recommendation. Set this value to attribute a user's interaction to a recommendation.
* @returns Resolves to true if successful. Otherwise, it will throw an exception.
*/
start(user_id: string, item_id: string, correlation_id?: string): 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.
*
* @param user_id The unique identifier of the user.
* @param item_id The unique identifier of the content item.
* @returns Resolves to true if successful. Otherwise, it will throw an exception.
*/
dislike(user_id: string, item_id: string): 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.
*
* @param user_id The unique identifier of the user.
* @param item_id The unique identifier of the content item.
* @returns Resolves to true if successful. Otherwise, it will throw an exception.
*/
like(user_id: string, item_id: string): Promise<boolean>;
/**
* 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.
*
* @param user_id The unique identifier of the user.
* @param num_items Number of content items that should be suggested.
* @returns Resolves to a `RecommendationResponse` if successful. Otherwise, it will throw an exception.
*/
recommend(user_id: string, num_items?: number): Promise<RecommendationsResponse>;
}