TypeScript turndown turndown示例

说明

typescript turndown turndown示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: TypeScript

命名空间/包名称: turndown

示例#1
文件: medication-dialog.ts 项目: LucasChies/Medication-Helper-idtpoa

    async (session: builder.Session, results: any, next?: (results?: builder.IDialogResult<any>) => void) => {

        // Formatting the response
        if (results && results.response) {
            let data = results.response;

            if (data.source == 'fr') {
                let drug: Medication = data.drug;

                // Brand Name
                session.send("**" + drug.denomination + "**");

                // Indications and Usage
                let indication_message = "Indications and Usage \n\n";
                let translatedIndications = await translator.getTranslationAsync(drug.indicationsTherapeutiques, 'fr', 'en');
                let turndown = new turndownService();
                if (translatedIndications) {
                    indication_message += turndown.turndown(translatedIndications);
                }
                session.send(indication_message);

                // Composition
                let composition_message = "Composition \n\n";
                for (var composition of drug.compositions) {
                    composition_message += `    └ ${composition.designationElementPharmaceutique} \n\n`;
                    for (var substance of composition.substancesActives) {
                        let translatedSubstance = await translator.getTranslationAsync(substance.denominationSubstance, 'fr', 'en');
                        composition_message += `        └ ${translatedSubstance} with a dosage of ${substance.dosageSubstance} \n\n`;
                    }
                }
                session.send(composition_message);
            }

            if (data.source == 'us') {
                let drug: Result = data.drug.results[0];

                // Brand Name
                session.send("**" + drug.openfda.brand_name[0] + "**");

                // Indications and Usage
                let indication_message = "Indications and Usage \n\n";
                indication_message += drug.indications_and_usage;
                session.send(indication_message);

                // Composition
                let composition_message = "Composition \n\n";
                if (drug.active_ingredient) {
                    for (let composition of drug.active_ingredient) {
                        composition_message += `    └ ${composition} \n\n`;
                    }
                }
                session.send(composition_message);
            }
        }

        return session.endDialog();
    }

示例#2
文件: medication-dialog.ts 项目: LucasChies/Medication-Helper-idtpoa

    async (session: builder.Session, results: any, next?: (results?: builder.IDialogResult<any>) => void) => {

        if (results && results.response) {
            session.dialogData.drug.country = results.response.country;
            session.dialogData.drug.countryCode = results.response.countryCode;
        }

        let data: ITranslateStoredData = session.dialogData.drug;

        // Ensure we have a languageCode
        let languageCode = undefined;
        if (data.languageCode) {
            languageCode = data.languageCode;
        }
        else if (data.countryCode) {
            let searchCountry = countrydata.getCountryByCountryCode(data.countryCode);
            if (searchCountry) {
                let language = languages[searchCountry.languages[0]];
                if (language) {
                    languageCode = language.alpha2;
                }
            }
        }

        // Formatting the response
        if (data.drugdetails.source == 'fr') {
            let drug: Medication = data.drugdetails.drug;

            session.send("substances_message");

            for (var composition of drug.compositions) {
                for (var substance of composition.substancesActives) {
                    let translatedSubstance = await translator.getTranslationAsync(substance.denominationSubstance, 'fr', languageCode);

                    if (translatedSubstance) {
                        let card = medicationcard.getMedicineCard(substance.denominationSubstance.toLowerCase(), translatedSubstance);

                        let message = new builder.Message(session).addAttachment(card);
                        session.send(message);
                    }
                }
            }

            if (drug.indicationsTherapeutiques) {
                let translatedIndications = await translator.getTranslationAsync(drug.indicationsTherapeutiques, 'fr', languageCode);
                let turndown = new turndownService();
                session.send(`Translated indications:\n\n` + turndown.turndown(translatedIndications));
            }
        }

        if (data.drugdetails.source == 'us') {
            let drug: Result = data.drugdetails.drug.results[0];

            session.send("substances_message");

            if (drug.openfda) {
                for (let substance of drug.openfda.substance_name) {
                    let translatedSubstance = await translator.getTranslationAsync(substance, 'en', languageCode);

                    if (translatedSubstance) {
                        let card = medicationcard.getMedicineCard(substance.toLowerCase(), translatedSubstance);

                        let message = new builder.Message(session).addAttachment(card);
                        session.send(message);
                    }
                }
            }

            if (drug.purpose) {
                let translatedIndications = await translator.getTranslationAsync(drug.purpose[0], 'en', languageCode);
                session.send(`Translated indications:\n\n` + translatedIndications);
            }
        }

        session.send("pharmacist_message");

        session.endDialog();
    }

展开阅读全文