@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
42 lines • 1.55 kB
JavaScript
import { Button, ContentCallback, PRIORITY_MAX, } 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(contentId, common, priority = PRIORITY_MAX) {
        this.contentId = contentId;
        this.common = common;
        this.priority = priority;
    }
    withResult(match, score) {
        return new SearchResult(this, match, score);
    }
}
export class SearchResult extends SearchCandidate {
    /**
     * @param match part of the input which match against a recognized text
     */
    constructor(candidate, match, score) {
        super(candidate.contentId, candidate.common, candidate.priority);
        this.match = match;
        this.score = score;
    }
    toButton() {
        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() {
        if (this.common.shortText !== SearchResult.CHITCHAT_SHORT_TEXT &&
            this.contentId.model !== ContentType.CHITCHAT) {
            return undefined;
        }
        return this.contentId;
    }
}
SearchResult.CHITCHAT_SHORT_TEXT = 'chitchat';
//# sourceMappingURL=search-result.js.map