UNPKG

@botonic/plugin-contentful

Version:

Botonic Plugin Contentful is one of the **[available](https://github.com/hubtype/botonic/tree/master/packages)** plugins for Botonic. **[Contentful](http://www.contentful.com)** is a CMS (Content Management System) which manages contents of a great variet

67 lines (60 loc) 1.57 kB
import { Button, CommonFields, ContentCallback, PRIORITY_MAX, TopContentId, } from '../cms' import { ContentType } from '../cms/cms' export class SearchCandidate { /** * @param contentId It may be a {@link Callback}'s with an URL instead of payload */ constructor( readonly contentId: TopContentId, readonly common: CommonFields, readonly priority = PRIORITY_MAX ) {} withResult(match: string, score: number): SearchResult { return new SearchResult(this, match, score) } } export class SearchResult extends SearchCandidate { static CHITCHAT_SHORT_TEXT = 'chitchat' /** * @param match part of the input which match against a recognized text */ constructor( candidate: SearchCandidate, readonly match: string, readonly score: number ) { super(candidate.contentId, candidate.common, candidate.priority) } toButton(): Button { let shortText = this.common.shortText if (!shortText) { shortText = this.common.name console.error( `${JSON.stringify(this.contentId)} ${ this.common.name } without shortText. Assigning name to button text` ) } return new Button( this.common.name, this.common.name, shortText, ContentCallback.ofContentId(this.contentId) ) } getCallbackIfChitchat(): TopContentId | undefined { if ( this.common.shortText !== SearchResult.CHITCHAT_SHORT_TEXT && this.contentId.model !== ContentType.CHITCHAT ) { return undefined } return this.contentId } }