diff --git a/samples/javascript_nodejs/02.echo-bot/bot.js b/samples/javascript_nodejs/02.echo-bot/bot.js index 9961988bef..c36b9b317d 100644 --- a/samples/javascript_nodejs/02.echo-bot/bot.js +++ b/samples/javascript_nodejs/02.echo-bot/bot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler, MessageFactory } = require('botbuilder'); class EchoBot extends ActivityHandler { @@ -15,7 +17,7 @@ class EchoBot extends ActivityHandler { }); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; const welcomeText = 'Hello and welcome!'; for (let cnt = 0; cnt < membersAdded.length; ++cnt) { if (membersAdded[cnt].id !== context.activity.recipient.id) { diff --git a/samples/javascript_nodejs/02.echo-bot/index.js b/samples/javascript_nodejs/02.echo-bot/index.js index a5d0989f2e..49558ea08f 100644 --- a/samples/javascript_nodejs/02.echo-bot/index.js +++ b/samples/javascript_nodejs/02.echo-bot/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const path = require('path'); const dotenv = require('dotenv'); diff --git a/samples/javascript_nodejs/03.welcome-users/bots/welcomeBot.js b/samples/javascript_nodejs/03.welcome-users/bots/welcomeBot.js index 3798c17592..df0ed8ef98 100644 --- a/samples/javascript_nodejs/03.welcome-users/bots/welcomeBot.js +++ b/samples/javascript_nodejs/03.welcome-users/bots/welcomeBot.js @@ -1,16 +1,20 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + // Import required Bot Framework classes. const { ActionTypes, ActivityHandler, CardFactory } = require('botbuilder'); +/** @import { UserState } from 'botbuilder' */ + // Welcomed User property name const WELCOMED_USER = 'welcomedUserProperty'; class WelcomeBot extends ActivityHandler { /** * - * @param {UserState} User state to persist boolean flag to indicate + * @param {UserState} userState to persist boolean flag to indicate * if the bot had already welcomed the user */ constructor(userState) { diff --git a/samples/javascript_nodejs/03.welcome-users/index.js b/samples/javascript_nodejs/03.welcome-users/index.js index c1609354dc..ab5d9e2e9c 100644 --- a/samples/javascript_nodejs/03.welcome-users/index.js +++ b/samples/javascript_nodejs/03.welcome-users/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + // Import required packages const path = require('path'); diff --git a/samples/javascript_nodejs/05.multi-turn-prompt/bots/dialogBot.js b/samples/javascript_nodejs/05.multi-turn-prompt/bots/dialogBot.js index fb4c107a8b..6a39bc9535 100644 --- a/samples/javascript_nodejs/05.multi-turn-prompt/bots/dialogBot.js +++ b/samples/javascript_nodejs/05.multi-turn-prompt/bots/dialogBot.js @@ -1,14 +1,19 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler } = require('botbuilder'); +/** @import { ConversationState, UserState } from 'botbuilder' */ +/** @import { UserProfileDialog } from '../dialogs/userProfileDialog' */ + class DialogBot extends ActivityHandler { /** * * @param {ConversationState} conversationState * @param {UserState} userState - * @param {Dialog} dialog + * @param {UserProfileDialog} dialog */ constructor(conversationState, userState, dialog) { super(); diff --git a/samples/javascript_nodejs/05.multi-turn-prompt/dialogs/userProfileDialog.js b/samples/javascript_nodejs/05.multi-turn-prompt/dialogs/userProfileDialog.js index a0905612c1..45458b6b4a 100644 --- a/samples/javascript_nodejs/05.multi-turn-prompt/dialogs/userProfileDialog.js +++ b/samples/javascript_nodejs/05.multi-turn-prompt/dialogs/userProfileDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { MessageFactory } = require('botbuilder'); const { AttachmentPrompt, @@ -112,7 +114,7 @@ class UserProfileDialog extends ComponentDialog { // We can send messages to the user at any point in the WaterfallStep. await step.context.sendActivity(msg); - if (step.context.activity.channelId === Channels.msteams) { + if (step.context.activity.channelId === Channels.Msteams) { // This attachment prompt example is not designed to work for Teams attachments, so skip it in this case await step.context.sendActivity('Skipping attachment prompt in Teams channel...'); return await step.next(undefined); diff --git a/samples/javascript_nodejs/05.multi-turn-prompt/index.js b/samples/javascript_nodejs/05.multi-turn-prompt/index.js index 8e331a9ee0..65463a6425 100644 --- a/samples/javascript_nodejs/05.multi-turn-prompt/index.js +++ b/samples/javascript_nodejs/05.multi-turn-prompt/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const restify = require('restify'); const path = require('path'); diff --git a/samples/javascript_nodejs/05.multi-turn-prompt/userProfile.js b/samples/javascript_nodejs/05.multi-turn-prompt/userProfile.js index c0b662e000..c3a3d037e6 100644 --- a/samples/javascript_nodejs/05.multi-turn-prompt/userProfile.js +++ b/samples/javascript_nodejs/05.multi-turn-prompt/userProfile.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + class UserProfile { constructor(transport, name, age, picture) { this.transport = transport; diff --git a/samples/javascript_nodejs/06.using-cards/bots/dialogBot.js b/samples/javascript_nodejs/06.using-cards/bots/dialogBot.js index 609dfb5700..ebf20c5cfc 100644 --- a/samples/javascript_nodejs/06.using-cards/bots/dialogBot.js +++ b/samples/javascript_nodejs/06.using-cards/bots/dialogBot.js @@ -1,8 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler } = require('botbuilder'); +/** @import { ConversationState, UserState } from 'botbuilder' */ +/** @import { MainDialog } from '../dialogs/mainDialog' */ + /** * This IBot implementation can run any type of Dialog. The use of type parameterization is to allows multiple different bots * to be run at different endpoints within the same project. This can be achieved by defining distinct Controller types @@ -15,7 +20,7 @@ class DialogBot extends ActivityHandler { * * @param {ConversationState} conversationState * @param {UserState} userState - * @param {Dialog} dialog + * @param {MainDialog} dialog */ constructor(conversationState, userState, dialog) { super(); diff --git a/samples/javascript_nodejs/06.using-cards/bots/richCardsBot.js b/samples/javascript_nodejs/06.using-cards/bots/richCardsBot.js index 6004657a05..25a9c79940 100644 --- a/samples/javascript_nodejs/06.using-cards/bots/richCardsBot.js +++ b/samples/javascript_nodejs/06.using-cards/bots/richCardsBot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { MessageFactory } = require('botbuilder'); const { DialogBot } = require('./dialogBot'); @@ -13,7 +15,7 @@ class RichCardsBot extends DialogBot { super(conversationState, userState, dialog); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; for (let cnt = 0; cnt < membersAdded.length; cnt++) { if (membersAdded[cnt].id !== context.activity.recipient.id) { const reply = MessageFactory.text('Welcome to CardBot. ' + diff --git a/samples/javascript_nodejs/06.using-cards/dialogs/mainDialog.js b/samples/javascript_nodejs/06.using-cards/dialogs/mainDialog.js index d73105fa32..b81d6b0344 100644 --- a/samples/javascript_nodejs/06.using-cards/dialogs/mainDialog.js +++ b/samples/javascript_nodejs/06.using-cards/dialogs/mainDialog.js @@ -1,12 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { AttachmentLayoutTypes, CardFactory } = require('botbuilder'); const { ChoicePrompt, ComponentDialog, DialogSet, DialogTurnStatus, WaterfallDialog } = require('botbuilder-dialogs'); const AdaptiveCard = require('../resources/adaptiveCard.json'); const MAIN_WATERFALL_DIALOG = 'mainWaterfallDialog'; +/** @import { WaterfallStepContext } from 'botbuilder-dialogs' */ + class MainDialog extends ComponentDialog { constructor() { super('MainDialog'); @@ -206,6 +210,7 @@ class MainDialog extends ComponentDialog { { subtitle: 'Star Wars: Episode V - The Empire Strikes Back', text: 'The Empire Strikes Back (also known as Star Wars: Episode V – The Empire Strikes Back) is a 1980 American epic space opera film directed by Irvin Kershner. Leigh Brackett and Lawrence Kasdan wrote the screenplay, with George Lucas writing the film\'s story and serving as executive producer. The second installment in the original Star Wars trilogy, it was produced by Gary Kurtz for Lucasfilm Ltd. and stars Mark Hamill, Harrison Ford, Carrie Fisher, Billy Dee Williams, Anthony Daniels, David Prowse, Kenny Baker, Peter Mayhew and Frank Oz.', + // @ts-ignore image: 'https://upload.wikimedia.org/wikipedia/en/3/3c/SW_-_Empire_Strikes_Back.jpg' } ); @@ -250,12 +255,14 @@ class MainDialog extends ComponentDialog { { title: 'Data Transfer', price: '$38.45', + // @ts-ignore quantity: 368, image: { url: 'https://github.com/amido/azure-vector-icons/raw/master/renders/traffic-manager.png' } }, { title: 'App Service', price: '$45.00', + // @ts-ignore quantity: 720, image: { url: 'https://github.com/amido/azure-vector-icons/raw/master/renders/cloud-service.png' } } diff --git a/samples/javascript_nodejs/06.using-cards/index.js b/samples/javascript_nodejs/06.using-cards/index.js index 1de9537e05..fdf7a5b201 100644 --- a/samples/javascript_nodejs/06.using-cards/index.js +++ b/samples/javascript_nodejs/06.using-cards/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + // index.js is used to setup and configure your bot // Import required packages diff --git a/samples/javascript_nodejs/07.using-adaptive-cards/bots/adaptiveCardsBot.js b/samples/javascript_nodejs/07.using-adaptive-cards/bots/adaptiveCardsBot.js index d0a487f479..12b7ba5345 100644 --- a/samples/javascript_nodejs/07.using-adaptive-cards/bots/adaptiveCardsBot.js +++ b/samples/javascript_nodejs/07.using-adaptive-cards/bots/adaptiveCardsBot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler, CardFactory } = require('botbuilder'); // Import AdaptiveCard content. @@ -25,7 +27,7 @@ class AdaptiveCardsBot extends ActivityHandler { constructor() { super(); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; for (let cnt = 0; cnt < membersAdded.length; cnt++) { if (membersAdded[cnt].id !== context.activity.recipient.id) { await context.sendActivity(`Welcome to Adaptive Cards Bot ${ membersAdded[cnt].name }. ${ WELCOME_TEXT }`); diff --git a/samples/javascript_nodejs/07.using-adaptive-cards/index.js b/samples/javascript_nodejs/07.using-adaptive-cards/index.js index 5a2ba17bbd..8c858cdc49 100644 --- a/samples/javascript_nodejs/07.using-adaptive-cards/index.js +++ b/samples/javascript_nodejs/07.using-adaptive-cards/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const path = require('path'); // Read botFilePath and botFileSecret from .env file. diff --git a/samples/javascript_nodejs/08.suggested-actions/bots/suggestedActionsBot.js b/samples/javascript_nodejs/08.suggested-actions/bots/suggestedActionsBot.js index 38a6e6ded5..a0e6bad1d3 100644 --- a/samples/javascript_nodejs/08.suggested-actions/bots/suggestedActionsBot.js +++ b/samples/javascript_nodejs/08.suggested-actions/bots/suggestedActionsBot.js @@ -1,9 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler, MessageFactory } = require('botbuilder'); const { ActionTypes } = require('botframework-schema'); +/** @import { TurnContext } from 'botbuilder' */ + class SuggestedActionsBot extends ActivityHandler { constructor() { super(); @@ -65,21 +69,21 @@ class SuggestedActionsBot extends ActivityHandler { type: ActionTypes.PostBack, title: 'Red', value: 'Red', - image: 'https://via.placeholder.com/20/FF0000?text=R', + image: 'https://placehold.co/20/red/red?text=R', imageAltText: 'R' }, { type: ActionTypes.PostBack, title: 'Yellow', value: 'Yellow', - image: 'https://via.placeholder.com/20/FFFF00?text=Y', + image: 'https://placehold.co/20/yellow/yellow?text=Y', imageAltText: 'Y' }, { type: ActionTypes.PostBack, title: 'Blue', value: 'Blue', - image: 'https://via.placeholder.com/20/0000FF?text=B', + image: 'https://placehold.co/20/blue/blue?text=B', imageAltText: 'B' } ]; diff --git a/samples/javascript_nodejs/08.suggested-actions/index.js b/samples/javascript_nodejs/08.suggested-actions/index.js index 949c37a8e3..bbe3c51124 100644 --- a/samples/javascript_nodejs/08.suggested-actions/index.js +++ b/samples/javascript_nodejs/08.suggested-actions/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const path = require('path'); // Read botFilePath and botFileSecret from .env file. diff --git a/samples/javascript_nodejs/12.customQABot/bots/CustomQABot.js b/samples/javascript_nodejs/12.customQABot/bots/CustomQABot.js index e813fd1eb6..f740d2c13c 100644 --- a/samples/javascript_nodejs/12.customQABot/bots/CustomQABot.js +++ b/samples/javascript_nodejs/12.customQABot/bots/CustomQABot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler, ActivityTypes } = require('botbuilder'); const { CustomQuestionAnswering } = require('botbuilder-ai'); @@ -10,9 +12,9 @@ class CustomQABot extends ActivityHandler { try { this.qnaMaker = new CustomQuestionAnswering({ - knowledgeBaseId: process.env.ProjectName, - endpointKey: process.env.LanguageEndpointKey, - host: process.env.LanguageEndpointHostName + knowledgeBaseId: process.env.ProjectName ?? '', + endpointKey: process.env.LanguageEndpointKey ?? '', + host: process.env.LanguageEndpointHostName ?? '' }); } catch (err) { console.warn(`QnAMaker Exception: ${ err } Check your QnAMaker configuration in .env`); @@ -20,11 +22,12 @@ class CustomQABot extends ActivityHandler { // If a new user is added to the conversation, send them a greeting message this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; for (let cnt = 0; cnt < membersAdded.length; cnt++) { if (membersAdded[cnt].id !== context.activity.recipient.id) { const DefaultWelcomeMessageFromConfig = process.env.DefaultWelcomeMessage; - await context.sendActivity(DefaultWelcomeMessageFromConfig?.length > 0 ? DefaultWelcomeMessageFromConfig : 'Hello and Welcome'); + const welcomeMessage = DefaultWelcomeMessageFromConfig && DefaultWelcomeMessageFromConfig.length > 0 ? DefaultWelcomeMessageFromConfig : 'Hello and Welcome'; + await context.sendActivity(welcomeMessage); } } @@ -45,10 +48,10 @@ class CustomQABot extends ActivityHandler { const enablePreciseAnswer = process.env.EnablePreciseAnswer === 'true'; const displayPreciseAnswerOnly = process.env.DisplayPreciseAnswerOnly === 'true'; - const response = await this.qnaMaker.getAnswers(context, { enablePreciseAnswer: enablePreciseAnswer }); + const response = await this.qnaMaker?.getAnswers(context, { enablePreciseAnswer: enablePreciseAnswer }); // If an answer was received from CQA, send the answer back to the user. - if (response.length > 0) { + if (response && response.length > 0) { var activities = []; var answerText = response[0].answer; diff --git a/samples/javascript_nodejs/12.customQABot/index.js b/samples/javascript_nodejs/12.customQABot/index.js index 93c623bfea..4547f3fc92 100644 --- a/samples/javascript_nodejs/12.customQABot/index.js +++ b/samples/javascript_nodejs/12.customQABot/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + // index.js is used to setup and configure your bot // Import required packages diff --git a/samples/javascript_nodejs/15.handling-attachments/bots/attachmentsBot.js b/samples/javascript_nodejs/15.handling-attachments/bots/attachmentsBot.js index 9aab0aa745..e929494a30 100644 --- a/samples/javascript_nodejs/15.handling-attachments/bots/attachmentsBot.js +++ b/samples/javascript_nodejs/15.handling-attachments/bots/attachmentsBot.js @@ -1,9 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler, ActionTypes, ActivityTypes, CardFactory } = require('botbuilder'); const path = require('path'); -const axios = require('axios'); +const axios = require('axios').default; const fs = require('fs'); class AttachmentsBot extends ActivityHandler { @@ -11,7 +13,7 @@ class AttachmentsBot extends ActivityHandler { super(); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; for (let cnt = 0; cnt < membersAdded.length; cnt++) { if (membersAdded[cnt].id !== context.activity.recipient.id) { // If the Activity is a ConversationUpdate, send a greeting message to the user. @@ -82,7 +84,6 @@ class AttachmentsBot extends ActivityHandler { // Use content.downloadURL if available as that contains needed auth token for working with ms teams const url = attachment.content?.downloadUrl || attachment.contentUrl; - // Local file path for the bot to save the attachment. const localFileName = path.join(__dirname, attachment.name); diff --git a/samples/javascript_nodejs/15.handling-attachments/index.js b/samples/javascript_nodejs/15.handling-attachments/index.js index 5885a76b02..044ab71663 100644 --- a/samples/javascript_nodejs/15.handling-attachments/index.js +++ b/samples/javascript_nodejs/15.handling-attachments/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const path = require('path'); // Read botFilePath and botFileSecret from .env file. diff --git a/samples/javascript_nodejs/16.proactive-messages/bots/proactiveBot.js b/samples/javascript_nodejs/16.proactive-messages/bots/proactiveBot.js index d401850de7..3c6b98a5c5 100644 --- a/samples/javascript_nodejs/16.proactive-messages/bots/proactiveBot.js +++ b/samples/javascript_nodejs/16.proactive-messages/bots/proactiveBot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler, TurnContext } = require('botbuilder'); class ProactiveBot extends ActivityHandler { @@ -17,7 +19,7 @@ class ProactiveBot extends ActivityHandler { }); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; for (let cnt = 0; cnt < membersAdded.length; cnt++) { if (membersAdded[cnt].id !== context.activity.recipient.id) { const welcomeMessage = 'Welcome to the Proactive Bot sample. Navigate to http://localhost:3978/api/notify to proactively message everyone who has previously messaged this bot.'; @@ -40,7 +42,10 @@ class ProactiveBot extends ActivityHandler { addConversationReference(activity) { const conversationReference = TurnContext.getConversationReference(activity); - this.conversationReferences[conversationReference.conversation.id] = conversationReference; + const conversationId = conversationReference.conversation?.id; + if (conversationId) { + this.conversationReferences[conversationId] = conversationReference; + } } } diff --git a/samples/javascript_nodejs/16.proactive-messages/index.js b/samples/javascript_nodejs/16.proactive-messages/index.js index c364ca3be9..a6a4908f38 100644 --- a/samples/javascript_nodejs/16.proactive-messages/index.js +++ b/samples/javascript_nodejs/16.proactive-messages/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + // index.js is used to setup and configure your bot // Import required packages @@ -72,7 +74,7 @@ server.post('/api/messages', async (req, res) => { // Listen for incoming notifications and send proactive messages to users. server.get('/api/notify', async (req, res) => { for (const conversationReference of Object.values(conversationReferences)) { - await adapter.continueConversationAsync(process.env.MicrosoftAppId, conversationReference, async context => { + await adapter.continueConversationAsync(process.env.MicrosoftAppId ?? '', conversationReference, async context => { await context.sendActivity('proactive hello'); }); } diff --git a/samples/javascript_nodejs/17.multilingual-bot/bots/multilingualBot.js b/samples/javascript_nodejs/17.multilingual-bot/bots/multilingualBot.js index b4f46ddc20..104d8e0574 100644 --- a/samples/javascript_nodejs/17.multilingual-bot/bots/multilingualBot.js +++ b/samples/javascript_nodejs/17.multilingual-bot/bots/multilingualBot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler, ActionTypes, CardFactory, MessageFactory } = require('botbuilder'); const { TranslationSettings } = require('../translation/translationSettings'); @@ -34,7 +36,7 @@ class MultilingualBot extends ActivityHandler { this.languagePreferenceProperty = languagePreferenceProperty; this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; for (let cnt = 0; cnt < membersAdded.length; cnt++) { if (membersAdded[cnt].id !== context.activity.recipient.id) { const welcomeCard = CardFactory.adaptiveCard(WelcomeCard); diff --git a/samples/javascript_nodejs/17.multilingual-bot/index.js b/samples/javascript_nodejs/17.multilingual-bot/index.js index 728538a399..5f72bf4f7e 100644 --- a/samples/javascript_nodejs/17.multilingual-bot/index.js +++ b/samples/javascript_nodejs/17.multilingual-bot/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + // index.js is used to setup and configure your bot // Import required packages. diff --git a/samples/javascript_nodejs/17.multilingual-bot/translation/microsoftTranslator.js b/samples/javascript_nodejs/17.multilingual-bot/translation/microsoftTranslator.js index 3f7b65265f..062b235238 100644 --- a/samples/javascript_nodejs/17.multilingual-bot/translation/microsoftTranslator.js +++ b/samples/javascript_nodejs/17.multilingual-bot/translation/microsoftTranslator.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const fetch = require('node-fetch'); class MicrosoftTranslator { diff --git a/samples/javascript_nodejs/17.multilingual-bot/translation/translationSettings.js b/samples/javascript_nodejs/17.multilingual-bot/translation/translationSettings.js index 2f76d35687..5603c1cb06 100644 --- a/samples/javascript_nodejs/17.multilingual-bot/translation/translationSettings.js +++ b/samples/javascript_nodejs/17.multilingual-bot/translation/translationSettings.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const TranslationSettings = { englishEnglish: 'en', englishSpanish: 'es', diff --git a/samples/javascript_nodejs/17.multilingual-bot/translation/translatorMiddleware.js b/samples/javascript_nodejs/17.multilingual-bot/translation/translatorMiddleware.js index 1bb51ae5b2..cdeeb8b82c 100644 --- a/samples/javascript_nodejs/17.multilingual-bot/translation/translatorMiddleware.js +++ b/samples/javascript_nodejs/17.multilingual-bot/translation/translatorMiddleware.js @@ -1,17 +1,22 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityTypes } = require('botbuilder'); const { TranslationSettings } = require('./translationSettings'); const DEFAULT_LANGUAGE = TranslationSettings.englishEnglish; +/** @import { StatePropertyAccessor } from 'botbuilder' */ +/** @import { MicrosoftTranslator } from '../translation/microsoftTranslator' */ + class TranslatorMiddleware { /** * Middleware for translating text between the user and bot. * Uses the Microsoft Translator Text API. - * @param {BotStatePropertyAccessor} languagePreferenceProperty Accessor for language preference property in the user state. - * @param {string} translatorKey Microsoft Text Translation API key. + * @param {MicrosoftTranslator} translator Translator implementation to be used for text translation. + * @param {StatePropertyAccessor} languagePreferenceProperty Accessor for language preference property in the user state. */ constructor(translator, languagePreferenceProperty) { if (!languagePreferenceProperty) { diff --git a/samples/javascript_nodejs/18.bot-authentication/bots/authBot.js b/samples/javascript_nodejs/18.bot-authentication/bots/authBot.js index dc36c12c2c..30d64adaa2 100644 --- a/samples/javascript_nodejs/18.bot-authentication/bots/authBot.js +++ b/samples/javascript_nodejs/18.bot-authentication/bots/authBot.js @@ -1,20 +1,25 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { DialogBot } = require('./dialogBot'); +/** @import { ConversationState, UserState } from 'botbuilder' */ +/** @import { MainDialog } from '../dialogs/mainDialog' */ + class AuthBot extends DialogBot { /** * * @param {ConversationState} conversationState * @param {UserState} userState - * @param {Dialog} dialog + * @param {MainDialog} dialog */ constructor(conversationState, userState, dialog) { super(conversationState, userState, dialog); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; for (let cnt = 0; cnt < membersAdded.length; cnt++) { if (membersAdded[cnt].id !== context.activity.recipient.id) { await context.sendActivity('Welcome to AuthenticationBot. Type anything to get logged in. Type \'logout\' to sign-out.'); diff --git a/samples/javascript_nodejs/18.bot-authentication/bots/dialogBot.js b/samples/javascript_nodejs/18.bot-authentication/bots/dialogBot.js index fb4c107a8b..aad53ab712 100644 --- a/samples/javascript_nodejs/18.bot-authentication/bots/dialogBot.js +++ b/samples/javascript_nodejs/18.bot-authentication/bots/dialogBot.js @@ -1,14 +1,19 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler } = require('botbuilder'); +/** @import { ConversationState, UserState } from 'botbuilder' */ +/** @import { MainDialog } from '../dialogs/mainDialog' */ + class DialogBot extends ActivityHandler { /** * * @param {ConversationState} conversationState * @param {UserState} userState - * @param {Dialog} dialog + * @param {MainDialog} dialog */ constructor(conversationState, userState, dialog) { super(); diff --git a/samples/javascript_nodejs/18.bot-authentication/dialogs/logoutDialog.js b/samples/javascript_nodejs/18.bot-authentication/dialogs/logoutDialog.js index d63e214096..167d593d06 100644 --- a/samples/javascript_nodejs/18.bot-authentication/dialogs/logoutDialog.js +++ b/samples/javascript_nodejs/18.bot-authentication/dialogs/logoutDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityTypes } = require('botbuilder'); const { ComponentDialog } = require('botbuilder-dialogs'); diff --git a/samples/javascript_nodejs/18.bot-authentication/dialogs/mainDialog.js b/samples/javascript_nodejs/18.bot-authentication/dialogs/mainDialog.js index 8684c61369..5a7dcec92f 100644 --- a/samples/javascript_nodejs/18.bot-authentication/dialogs/mainDialog.js +++ b/samples/javascript_nodejs/18.bot-authentication/dialogs/mainDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ConfirmPrompt, DialogSet, DialogTurnStatus, OAuthPrompt, WaterfallDialog } = require('botbuilder-dialogs'); const { LogoutDialog } = require('./logoutDialog'); @@ -15,7 +17,7 @@ class MainDialog extends LogoutDialog { super(MAIN_DIALOG, process.env.connectionName); this.addDialog(new OAuthPrompt(OAUTH_PROMPT, { - connectionName: process.env.connectionName, + connectionName: process.env.connectionName ?? '', text: 'Please Sign In', title: 'Sign In', timeout: 300000 @@ -34,7 +36,7 @@ class MainDialog extends LogoutDialog { /** * The run method handles the incoming activity (in the form of a DialogContext) and passes it through the dialog system. * If no dialog is active, it will start the default dialog. - * @param {*} dialogContext + * @param {*} context The dialogContext. */ async run(context, accessor) { const dialogSet = new DialogSet(accessor); diff --git a/samples/javascript_nodejs/18.bot-authentication/index.js b/samples/javascript_nodejs/18.bot-authentication/index.js index d530fb9642..b23ec9d090 100644 --- a/samples/javascript_nodejs/18.bot-authentication/index.js +++ b/samples/javascript_nodejs/18.bot-authentication/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + // index.js is used to setup and configure your bot // Import required pckages diff --git a/samples/javascript_nodejs/19.custom-dialogs/bots/dialogBot.js b/samples/javascript_nodejs/19.custom-dialogs/bots/dialogBot.js index 18e6453743..67d565a689 100644 --- a/samples/javascript_nodejs/19.custom-dialogs/bots/dialogBot.js +++ b/samples/javascript_nodejs/19.custom-dialogs/bots/dialogBot.js @@ -1,14 +1,19 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler } = require('botbuilder'); +/** @import { ConversationState, UserState } from 'botbuilder' */ +/** @import { RootDialog } from '../dialogs/rootDialog' */ + class DialogBot extends ActivityHandler { /** * * @param {ConversationState} conversationState * @param {UserState} userState - * @param {Dialog} dialog + * @param {RootDialog} dialog */ constructor(conversationState, userState, dialog) { super(); diff --git a/samples/javascript_nodejs/19.custom-dialogs/dialogs/rootDialog.js b/samples/javascript_nodejs/19.custom-dialogs/dialogs/rootDialog.js index f39d34da42..8913f3bbd7 100644 --- a/samples/javascript_nodejs/19.custom-dialogs/dialogs/rootDialog.js +++ b/samples/javascript_nodejs/19.custom-dialogs/dialogs/rootDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ComponentDialog, DialogSet, @@ -12,10 +14,12 @@ const { const { SlotDetails } = require('./slotDetails'); const { SlotFillingDialog } = require('./slotFillingDialog'); +/** @import { UserState } from 'botbuilder' */ + class RootDialog extends ComponentDialog { /** * SampleBot defines the core business logic of this bot. - * @param {ConversationState} conversationState A ConversationState object used to store dialog state. + * @param {UserState} userState A ConversationState object used to store dialog state. */ constructor(userState) { super('root'); @@ -25,23 +29,25 @@ class RootDialog extends ComponentDialog { // Set up a series of questions for collecting the user's name. const fullnameSlots = [ - new SlotDetails('first', 'text', 'Please enter your first name.'), - new SlotDetails('last', 'text', 'Please enter your last name.') + new SlotDetails('first', 'text', 'Please enter your first name.', ''), + new SlotDetails('last', 'text', 'Please enter your last name.', '') ]; // Set up a series of questions to collect a street address. const addressSlots = [ - new SlotDetails('street', 'text', 'Please enter your street address.'), - new SlotDetails('city', 'text', 'Please enter the city.'), - new SlotDetails('zip', 'text', 'Please enter your zipcode.') + new SlotDetails('street', 'text', 'Please enter your street address.', ''), + new SlotDetails('city', 'text', 'Please enter the city.', ''), + new SlotDetails('zip', 'text', 'Please enter your zipcode.', '') ]; // Link the questions together into a parent group that contains references // to both the fullname and address questions defined above. const slots = [ + // @ts-ignore new SlotDetails('fullname', 'fullname'), - new SlotDetails('age', 'number', 'Please enter your age.'), + new SlotDetails('age', 'number', 'Please enter your age.', ''), new SlotDetails('shoesize', 'shoesize', 'Please enter your shoe size.', 'You must enter a size between 0 and 16. Half sizes are acceptable.'), + // @ts-ignore new SlotDetails('address', 'address') ]; @@ -68,7 +74,7 @@ class RootDialog extends ComponentDialog { /** * The run method handles the incoming activity (in the form of a DialogContext) and passes it through the dialog system. * If no dialog is active, it will start the default dialog. - * @param {*} dialogContext + * @param {*} context The dialogContext. */ async run(context, accessor) { const dialogSet = new DialogSet(accessor); diff --git a/samples/javascript_nodejs/19.custom-dialogs/dialogs/slotDetails.js b/samples/javascript_nodejs/19.custom-dialogs/dialogs/slotDetails.js index 81be42d0a4..4d13156e9c 100644 --- a/samples/javascript_nodejs/19.custom-dialogs/dialogs/slotDetails.js +++ b/samples/javascript_nodejs/19.custom-dialogs/dialogs/slotDetails.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + class SlotDetails { /** * SlotDetails is a small class that defines a "slot" to be filled in a SlotFillingDialog. diff --git a/samples/javascript_nodejs/19.custom-dialogs/dialogs/slotFillingDialog.js b/samples/javascript_nodejs/19.custom-dialogs/dialogs/slotFillingDialog.js index 76740831c9..1df8cba9ea 100644 --- a/samples/javascript_nodejs/19.custom-dialogs/dialogs/slotFillingDialog.js +++ b/samples/javascript_nodejs/19.custom-dialogs/dialogs/slotFillingDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityTypes } = require('botbuilder'); const { Dialog } = require('botbuilder-dialogs'); diff --git a/samples/javascript_nodejs/19.custom-dialogs/index.js b/samples/javascript_nodejs/19.custom-dialogs/index.js index f6ae9483f1..961099bce1 100644 --- a/samples/javascript_nodejs/19.custom-dialogs/index.js +++ b/samples/javascript_nodejs/19.custom-dialogs/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const restify = require('restify'); const path = require('path'); diff --git a/samples/javascript_nodejs/23.facebook-events/bots/facebookBot.js b/samples/javascript_nodejs/23.facebook-events/bots/facebookBot.js index c49fc3954c..c2792751aa 100644 --- a/samples/javascript_nodejs/23.facebook-events/bots/facebookBot.js +++ b/samples/javascript_nodejs/23.facebook-events/bots/facebookBot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler, CardFactory, ActionTypes } = require('botbuilder'); const { ChoiceFactory } = require('botbuilder-dialogs'); // These are the options provided to the user when they message the bot @@ -154,7 +156,7 @@ class FacebookBot extends ActivityHandler { case postBackOption: var card = CardFactory.heroCard( 'Is 42 the answer to the ultimate question of Life, the Universe, and Everything?', - null, + [], CardFactory.actions([ { type: ActionTypes.PostBack, diff --git a/samples/javascript_nodejs/23.facebook-events/index.js b/samples/javascript_nodejs/23.facebook-events/index.js index 6c5c56ef8e..42f9097ccb 100644 --- a/samples/javascript_nodejs/23.facebook-events/index.js +++ b/samples/javascript_nodejs/23.facebook-events/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + // index.js is used to setup and configure your bot // Import required packages diff --git a/samples/javascript_nodejs/24.bot-authentication-msgraph/bots/authBot.js b/samples/javascript_nodejs/24.bot-authentication-msgraph/bots/authBot.js index 93cce535d6..7b6d0b0b38 100644 --- a/samples/javascript_nodejs/24.bot-authentication-msgraph/bots/authBot.js +++ b/samples/javascript_nodejs/24.bot-authentication-msgraph/bots/authBot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { DialogBot } = require('./dialogBot'); class AuthBot extends DialogBot { @@ -8,7 +10,7 @@ class AuthBot extends DialogBot { super(conversationState, userState, dialog); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; for (let cnt = 0; cnt < membersAdded.length; cnt++) { if (membersAdded[cnt].id !== context.activity.recipient.id) { await context.sendActivity('Welcome to Authentication Bot on MSGraph. Type anything to get logged in. Type \'logout\' to sign-out.'); diff --git a/samples/javascript_nodejs/24.bot-authentication-msgraph/bots/dialogBot.js b/samples/javascript_nodejs/24.bot-authentication-msgraph/bots/dialogBot.js index e5baeb19ce..868d8d68d6 100644 --- a/samples/javascript_nodejs/24.bot-authentication-msgraph/bots/dialogBot.js +++ b/samples/javascript_nodejs/24.bot-authentication-msgraph/bots/dialogBot.js @@ -1,14 +1,19 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { TeamsActivityHandler } = require('botbuilder'); +/** @import { ConversationState, UserState } from 'botbuilder' */ +/** @import { MainDialog } from '../dialogs/mainDialog' */ + class DialogBot extends TeamsActivityHandler { /** * * @param {ConversationState} conversationState * @param {UserState} userState - * @param {Dialog} dialog + * @param {MainDialog} dialog */ constructor(conversationState, userState, dialog) { super(); diff --git a/samples/javascript_nodejs/24.bot-authentication-msgraph/dialogs/logoutDialog.js b/samples/javascript_nodejs/24.bot-authentication-msgraph/dialogs/logoutDialog.js index d71ee69c1a..7794d5c5cc 100644 --- a/samples/javascript_nodejs/24.bot-authentication-msgraph/dialogs/logoutDialog.js +++ b/samples/javascript_nodejs/24.bot-authentication-msgraph/dialogs/logoutDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityTypes } = require('botbuilder'); const { ComponentDialog } = require('botbuilder-dialogs'); diff --git a/samples/javascript_nodejs/24.bot-authentication-msgraph/dialogs/mainDialog.js b/samples/javascript_nodejs/24.bot-authentication-msgraph/dialogs/mainDialog.js index 1e69e5a01e..67efa4cb68 100644 --- a/samples/javascript_nodejs/24.bot-authentication-msgraph/dialogs/mainDialog.js +++ b/samples/javascript_nodejs/24.bot-authentication-msgraph/dialogs/mainDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ChoicePrompt, DialogSet, DialogTurnStatus, OAuthPrompt, TextPrompt, WaterfallDialog } = require('botbuilder-dialogs'); const { LogoutDialog } = require('./logoutDialog'); const { OAuthHelpers } = require('../oAuthHelpers'); @@ -12,10 +14,10 @@ const TEXT_PROMPT = 'textPrompt'; class MainDialog extends LogoutDialog { constructor() { - super('MainDialog', process.env.connectionName); + super('MainDialog', process.env.ConnectionName); this.addDialog(new ChoicePrompt(CHOICE_PROMPT)) .addDialog(new OAuthPrompt(OAUTH_PROMPT, { - connectionName: process.env.ConnectionName, + connectionName: process.env.ConnectionName ?? '', text: 'Please login', title: 'Login', timeout: 300000 diff --git a/samples/javascript_nodejs/24.bot-authentication-msgraph/index.js b/samples/javascript_nodejs/24.bot-authentication-msgraph/index.js index 929048cfb2..3cc6692a6b 100644 --- a/samples/javascript_nodejs/24.bot-authentication-msgraph/index.js +++ b/samples/javascript_nodejs/24.bot-authentication-msgraph/index.js @@ -1,5 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. + +// @ts-check + const restify = require('restify'); const path = require('path'); require('isomorphic-fetch'); diff --git a/samples/javascript_nodejs/24.bot-authentication-msgraph/oAuthHelpers.js b/samples/javascript_nodejs/24.bot-authentication-msgraph/oAuthHelpers.js index 20cdf3d75e..9c821ae9e6 100644 --- a/samples/javascript_nodejs/24.bot-authentication-msgraph/oAuthHelpers.js +++ b/samples/javascript_nodejs/24.bot-authentication-msgraph/oAuthHelpers.js @@ -1,8 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { SimpleGraphClient } = require('./simple-graph-client'); +/** @import { TokenResponse, TurnContext } from 'botbuilder' */ + /** * These methods call the Microsoft Graph API. The following OAuth scopes are used: * 'openid' 'profile' 'User.Read' diff --git a/samples/javascript_nodejs/24.bot-authentication-msgraph/simple-graph-client.js b/samples/javascript_nodejs/24.bot-authentication-msgraph/simple-graph-client.js index a01fe3a3a5..de02dc7289 100644 --- a/samples/javascript_nodejs/24.bot-authentication-msgraph/simple-graph-client.js +++ b/samples/javascript_nodejs/24.bot-authentication-msgraph/simple-graph-client.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { Client } = require('@microsoft/microsoft-graph-client'); /** diff --git a/samples/javascript_nodejs/40.timex-resolution/ambiguity.js b/samples/javascript_nodejs/40.timex-resolution/ambiguity.js index 648385dd37..7833bbeadd 100644 --- a/samples/javascript_nodejs/40.timex-resolution/ambiguity.js +++ b/samples/javascript_nodejs/40.timex-resolution/ambiguity.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const Recognizers = require('@microsoft/recognizers-text-date-time'); // TIMEX expressions are designed to represent ambiguous rather than definite dates. diff --git a/samples/javascript_nodejs/40.timex-resolution/constraints.js b/samples/javascript_nodejs/40.timex-resolution/constraints.js index 72282d8903..b6daa0856e 100644 --- a/samples/javascript_nodejs/40.timex-resolution/constraints.js +++ b/samples/javascript_nodejs/40.timex-resolution/constraints.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { creator, resolver } = require('@microsoft/recognizers-text-data-types-timex-expression'); // The TimexRangeResolved can be used in application logic to apply constraints to a set of TIMEX expressions. diff --git a/samples/javascript_nodejs/40.timex-resolution/index.js b/samples/javascript_nodejs/40.timex-resolution/index.js index dd681ef352..0ff5a562ab 100644 --- a/samples/javascript_nodejs/40.timex-resolution/index.js +++ b/samples/javascript_nodejs/40.timex-resolution/index.js @@ -2,6 +2,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const ambiguity = require('./ambiguity.js'); const constraints = require('./constraints.js'); const languageGeneration = require('./languageGeneration.js'); diff --git a/samples/javascript_nodejs/40.timex-resolution/languageGeneration.js b/samples/javascript_nodejs/40.timex-resolution/languageGeneration.js index 2503dd93e7..7c2fcbe05e 100644 --- a/samples/javascript_nodejs/40.timex-resolution/languageGeneration.js +++ b/samples/javascript_nodejs/40.timex-resolution/languageGeneration.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { TimexProperty } = require('@microsoft/recognizers-text-data-types-timex-expression'); // This langauge generation capabilitis are the logical opposite of what the recognizer does. diff --git a/samples/javascript_nodejs/40.timex-resolution/parsing.js b/samples/javascript_nodejs/40.timex-resolution/parsing.js index fb7b8851f9..82b0e734d2 100644 --- a/samples/javascript_nodejs/40.timex-resolution/parsing.js +++ b/samples/javascript_nodejs/40.timex-resolution/parsing.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { TimexProperty } = require('@microsoft/recognizers-text-data-types-timex-expression'); // The TimexProperty class takes a TIMEX expression as a string argument in its constructor. diff --git a/samples/javascript_nodejs/40.timex-resolution/ranges.js b/samples/javascript_nodejs/40.timex-resolution/ranges.js index 8025492487..c058282f80 100644 --- a/samples/javascript_nodejs/40.timex-resolution/ranges.js +++ b/samples/javascript_nodejs/40.timex-resolution/ranges.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const Recognizers = require('@microsoft/recognizers-text-date-time'); module.exports.dateRange = () => { diff --git a/samples/javascript_nodejs/40.timex-resolution/resolution.js b/samples/javascript_nodejs/40.timex-resolution/resolution.js index 0d444dd263..0d1f5e6995 100644 --- a/samples/javascript_nodejs/40.timex-resolution/resolution.js +++ b/samples/javascript_nodejs/40.timex-resolution/resolution.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { valueResolver } = require('@microsoft/recognizers-text-data-types-timex-expression'); // Given the TIMEX expressions it is easy to create the computed example values that the recognizer gives. diff --git a/samples/javascript_nodejs/43.complex-dialog/bots/dialogAndWelcomeBot.js b/samples/javascript_nodejs/43.complex-dialog/bots/dialogAndWelcomeBot.js index 64ef7034e4..fecafaaf03 100644 --- a/samples/javascript_nodejs/43.complex-dialog/bots/dialogAndWelcomeBot.js +++ b/samples/javascript_nodejs/43.complex-dialog/bots/dialogAndWelcomeBot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { DialogBot } = require('./dialogBot'); class DialogAndWelcomeBot extends DialogBot { @@ -8,7 +10,7 @@ class DialogAndWelcomeBot extends DialogBot { super(conversationState, userState, dialog); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; for (let cnt = 0; cnt < membersAdded.length; cnt++) { if (membersAdded[cnt].id !== context.activity.recipient.id) { const reply = `Welcome to Complex Dialog Bot ${ membersAdded[cnt].name }. This bot provides a complex conversation, with multiple dialogs. Type anything to get started.`; diff --git a/samples/javascript_nodejs/43.complex-dialog/bots/dialogBot.js b/samples/javascript_nodejs/43.complex-dialog/bots/dialogBot.js index 18e6453743..1e7d898e8c 100644 --- a/samples/javascript_nodejs/43.complex-dialog/bots/dialogBot.js +++ b/samples/javascript_nodejs/43.complex-dialog/bots/dialogBot.js @@ -1,14 +1,19 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler } = require('botbuilder'); +/** @import { ConversationState, UserState } from 'botbuilder' */ +/** @import { MainDialog } from '../dialogs/mainDialog' */ + class DialogBot extends ActivityHandler { /** * * @param {ConversationState} conversationState * @param {UserState} userState - * @param {Dialog} dialog + * @param {MainDialog} dialog */ constructor(conversationState, userState, dialog) { super(); diff --git a/samples/javascript_nodejs/43.complex-dialog/dialogs/mainDialog.js b/samples/javascript_nodejs/43.complex-dialog/dialogs/mainDialog.js index bd7e8a0b51..5130bfdf5c 100644 --- a/samples/javascript_nodejs/43.complex-dialog/dialogs/mainDialog.js +++ b/samples/javascript_nodejs/43.complex-dialog/dialogs/mainDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ComponentDialog, DialogSet, DialogTurnStatus, WaterfallDialog } = require('botbuilder-dialogs'); const { TopLevelDialog, TOP_LEVEL_DIALOG } = require('./topLevelDialog'); diff --git a/samples/javascript_nodejs/43.complex-dialog/dialogs/reviewSelectionDialog.js b/samples/javascript_nodejs/43.complex-dialog/dialogs/reviewSelectionDialog.js index d03942806c..681dca303a 100644 --- a/samples/javascript_nodejs/43.complex-dialog/dialogs/reviewSelectionDialog.js +++ b/samples/javascript_nodejs/43.complex-dialog/dialogs/reviewSelectionDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ChoicePrompt, ComponentDialog, WaterfallDialog } = require('botbuilder-dialogs'); const REVIEW_SELECTION_DIALOG = 'REVIEW_SELECTION_DIALOG'; diff --git a/samples/javascript_nodejs/43.complex-dialog/dialogs/topLevelDialog.js b/samples/javascript_nodejs/43.complex-dialog/dialogs/topLevelDialog.js index 767964dd6a..1589bf9ba8 100644 --- a/samples/javascript_nodejs/43.complex-dialog/dialogs/topLevelDialog.js +++ b/samples/javascript_nodejs/43.complex-dialog/dialogs/topLevelDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ComponentDialog, NumberPrompt, TextPrompt, WaterfallDialog } = require('botbuilder-dialogs'); const { ReviewSelectionDialog, REVIEW_SELECTION_DIALOG } = require('./reviewSelectionDialog'); const { UserProfile } = require('../userProfile'); diff --git a/samples/javascript_nodejs/43.complex-dialog/index.js b/samples/javascript_nodejs/43.complex-dialog/index.js index 09a165de4a..e177662074 100644 --- a/samples/javascript_nodejs/43.complex-dialog/index.js +++ b/samples/javascript_nodejs/43.complex-dialog/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const path = require('path'); // Read environment variables from .env file diff --git a/samples/javascript_nodejs/43.complex-dialog/userProfile.js b/samples/javascript_nodejs/43.complex-dialog/userProfile.js index 8863d614c4..7af4ffde76 100644 --- a/samples/javascript_nodejs/43.complex-dialog/userProfile.js +++ b/samples/javascript_nodejs/43.complex-dialog/userProfile.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + class UserProfile { constructor(name, age) { this.name = name; diff --git a/samples/javascript_nodejs/44.prompt-for-user-input/bots/customPromptBot.js b/samples/javascript_nodejs/44.prompt-for-user-input/bots/customPromptBot.js index 7527db861b..d40fb700c8 100644 --- a/samples/javascript_nodejs/44.prompt-for-user-input/bots/customPromptBot.js +++ b/samples/javascript_nodejs/44.prompt-for-user-input/bots/customPromptBot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const Recognizers = require('@microsoft/recognizers-text-suite'); const { ActivityHandler } = require('botbuilder'); @@ -122,8 +124,8 @@ class CustomPromptBot extends ActivityHandler { static validateName(input) { const name = input && input.trim(); return name !== undefined - ? { success: true, name: name } - : { success: false, message: 'Please enter a name that contains at least one character.' }; + ? { success: true, name: name, message: '' } + : { success: false, name: null, message: 'Please enter a name that contains at least one character.' }; }; // Validates age input. Returns whether validation succeeded and either the parsed and normalized @@ -141,15 +143,16 @@ class CustomPromptBot extends ActivityHandler { if (value) { const age = parseInt(value); if (!isNaN(age) && age >= 18 && age <= 120) { - output = { success: true, age: age }; + output = { success: true, age: age, message: '' }; return; } } }); - return output || { success: false, message: 'Please enter an age between 18 and 120.' }; + return output || { success: false, age: null, message: 'Please enter an age between 18 and 120.' }; } catch (error) { return { success: false, + age: null, message: "I'm sorry, I could not interpret that as an age. Please enter an age between 18 and 120." }; } @@ -176,15 +179,16 @@ class CustomPromptBot extends ActivityHandler { ? new Date(`${ now.toLocaleDateString() } ${ datevalue }`) : new Date(datevalue); if (datetime && earliest < datetime.getTime()) { - output = { success: true, date: datetime.toLocaleDateString() }; + output = { success: true, date: datetime.toISOString(), message: '' }; return; } }); }); - return output || { success: false, message: "I'm sorry, please enter a date at least an hour out." }; + return output || { success: false, date: null, message: "I'm sorry, please enter a date at least an hour out." }; } catch (error) { return { success: false, + date: null, message: "I'm sorry, I could not interpret that as an appropriate date. Please enter a date at least an hour out." }; } diff --git a/samples/javascript_nodejs/44.prompt-for-user-input/index.js b/samples/javascript_nodejs/44.prompt-for-user-input/index.js index 699a8c656b..a605b1e12a 100644 --- a/samples/javascript_nodejs/44.prompt-for-user-input/index.js +++ b/samples/javascript_nodejs/44.prompt-for-user-input/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const path = require('path'); // Read environment variables from .env file diff --git a/samples/javascript_nodejs/45.state-management/bots/stateManagementBot.js b/samples/javascript_nodejs/45.state-management/bots/stateManagementBot.js index 4435bc9425..84474a7669 100644 --- a/samples/javascript_nodejs/45.state-management/bots/stateManagementBot.js +++ b/samples/javascript_nodejs/45.state-management/bots/stateManagementBot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler } = require('botbuilder'); // The accessor names for the conversation data and user profile state property accessors. @@ -44,7 +46,7 @@ class StateManagementBot extends ActivityHandler { } } else { // Add message details to the conversation data. - conversationData.timestamp = turnContext.activity.timestamp.toLocaleString(); + conversationData.timestamp = turnContext.activity.timestamp?.toLocaleString(); conversationData.channelId = turnContext.activity.channelId; // Display state data. @@ -58,7 +60,7 @@ class StateManagementBot extends ActivityHandler { }); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; for (let cnt = 0; cnt < membersAdded.length; ++cnt) { if (membersAdded[cnt].id !== context.activity.recipient.id) { await context.sendActivity('Welcome to State Bot Sample. Type anything to get started.'); diff --git a/samples/javascript_nodejs/45.state-management/index.js b/samples/javascript_nodejs/45.state-management/index.js index eebec8dab4..af225cc5d4 100644 --- a/samples/javascript_nodejs/45.state-management/index.js +++ b/samples/javascript_nodejs/45.state-management/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const path = require('path'); // Read environment variables from .env file diff --git a/samples/javascript_nodejs/47.inspection/bot.js b/samples/javascript_nodejs/47.inspection/bot.js index 9bc5c95710..f431b01b8e 100644 --- a/samples/javascript_nodejs/47.inspection/bot.js +++ b/samples/javascript_nodejs/47.inspection/bot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler } = require('botbuilder'); class IntersectionBot extends ActivityHandler { @@ -28,7 +30,7 @@ class IntersectionBot extends ActivityHandler { }); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; for (let cnt = 0; cnt < membersAdded.length; ++cnt) { if (membersAdded[cnt].id !== context.activity.recipient.id) { await context.sendActivity('Hello and welcome!'); diff --git a/samples/javascript_nodejs/47.inspection/index.js b/samples/javascript_nodejs/47.inspection/index.js index 88a73b57e0..a89ea0fee4 100644 --- a/samples/javascript_nodejs/47.inspection/index.js +++ b/samples/javascript_nodejs/47.inspection/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const dotenv = require('dotenv'); const path = require('path'); @@ -50,7 +52,7 @@ const userState = new UserState(memoryStorage); const conversationState = new ConversationState(memoryStorage); // Create and add the InspectionMiddleware to the adapter. -adapter.use(new InspectionMiddleware(inspectionState, userState, conversationState, new MicrosoftAppCredentials(process.env.MicrosoftAppId, process.env.MicrosoftAppPassword))); +adapter.use(new InspectionMiddleware(inspectionState, userState, conversationState, new MicrosoftAppCredentials(process.env.MicrosoftAppId ?? '', process.env.MicrosoftAppPassword ?? ''))); // Catch-all for errors. adapter.onTurnError = async (context, error) => { diff --git a/samples/javascript_nodejs/48.customQABot-all-features/bots/CustomQABot.js b/samples/javascript_nodejs/48.customQABot-all-features/bots/CustomQABot.js index c5bf213f7f..15cd138234 100644 --- a/samples/javascript_nodejs/48.customQABot-all-features/bots/CustomQABot.js +++ b/samples/javascript_nodejs/48.customQABot-all-features/bots/CustomQABot.js @@ -1,8 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler } = require('botbuilder'); +/** @import { ConversationState, UserState } from 'botbuilder' */ +/** @import { RootDialog } from '../dialogs/rootDialog' */ + /** * A simple bot that responds to utterances with answers from QnA Maker. * If an answer is not found for an utterance, the bot responds with help. @@ -12,7 +17,7 @@ class CustomQABot extends ActivityHandler { * * @param {ConversationState} conversationState * @param {UserState} userState - * @param {Dialog} dialog + * @param {RootDialog} dialog */ constructor(conversationState, userState, dialog) { super(); @@ -37,10 +42,10 @@ class CustomQABot extends ActivityHandler { // If a new user is added to the conversation, send them a greeting message this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; for (let cnt = 0; cnt < membersAdded.length; cnt++) { if (membersAdded[cnt].id !== context.activity.recipient.id) { - const defaultWelcome = process.env.DefaultWelcomeMessage; + const defaultWelcome = process.env.DefaultWelcomeMessage ?? ''; if (defaultWelcome !== '') await context.sendActivity(defaultWelcome); else await context.sendActivity('Welcome to the QnA Maker sample! Ask me a question and I will try to answer it.'); } diff --git a/samples/javascript_nodejs/48.customQABot-all-features/dialogs/rootDialog.js b/samples/javascript_nodejs/48.customQABot-all-features/dialogs/rootDialog.js index ad5533cbee..3d628f5109 100644 --- a/samples/javascript_nodejs/48.customQABot-all-features/dialogs/rootDialog.js +++ b/samples/javascript_nodejs/48.customQABot-all-features/dialogs/rootDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +// @ts-check + const { QnAMakerDialog, RankerTypes } = require('botbuilder-ai'); const { ComponentDialog, @@ -36,6 +38,7 @@ const createQnAMakerDialog = (knowledgeBaseId, endpointKey, endpointHostName, de knowledgeBaseId, endpointKey, endpointHostName, + // @ts-ignore noAnswerActivity, SCORE_THRESHOLD, ACTIVE_LEARNING_CARD_TITLE, @@ -81,7 +84,7 @@ class RootDialog extends ComponentDialog { /** * The run method handles the incoming activity (in the form of a TurnContext) and passes it through the dialog system. * If no dialog is active, it will start the default dialog. - * @param {*} turnContext + * @param {*} context turnContext * @param {*} accessor */ async run(context, accessor) { diff --git a/samples/javascript_nodejs/48.customQABot-all-features/index.js b/samples/javascript_nodejs/48.customQABot-all-features/index.js index cce3ae2629..57f8967b51 100644 --- a/samples/javascript_nodejs/48.customQABot-all-features/index.js +++ b/samples/javascript_nodejs/48.customQABot-all-features/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +// @ts-check + // index.js is used to setup and configure your bot // Import required packages @@ -59,7 +61,7 @@ const conversationState = new ConversationState(memoryStorage); const userState = new UserState(memoryStorage); var endpointHostName = process.env.LanguageEndpointHostName; -if (!endpointHostName.startsWith('https://')) { +if (!endpointHostName?.startsWith('https://')) { endpointHostName = 'https://' + endpointHostName; } @@ -68,13 +70,13 @@ const endpointKey = process.env.LanguageEndpointKey || process.env.QnAAuthKey; // Create the main dialog. const dialog = new RootDialog( - process.env.ProjectName, - endpointKey, + process.env.ProjectName ?? '', + endpointKey ?? '', endpointHostName, - process.env.DefaultAnswer, - process.env.EnablePreciseAnswer.toLowerCase(), - process.env.DisplayPreciseAnswerOnly.toLowerCase(), - process.env.UseTeamsAdaptiveCard.toLowerCase()); + process.env.DefaultAnswer ?? '', + process.env.EnablePreciseAnswer?.toLowerCase() ?? 'false', + process.env.DisplayPreciseAnswerOnly?.toLowerCase() ?? 'false', + process.env.UseTeamsAdaptiveCard?.toLowerCase()); // Create the bot's main handler. const bot = new CustomQABot(conversationState, userState, dialog); diff --git a/samples/javascript_nodejs/49.echo-proxy-bot/bot.js b/samples/javascript_nodejs/49.echo-proxy-bot/bot.js index f8bdaecc7c..2ea644bd25 100644 --- a/samples/javascript_nodejs/49.echo-proxy-bot/bot.js +++ b/samples/javascript_nodejs/49.echo-proxy-bot/bot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler, MessageFactory } = require('botbuilder'); class EchoProxyBot extends ActivityHandler { @@ -15,7 +17,7 @@ class EchoProxyBot extends ActivityHandler { }); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; const welcomeText = 'Hello and welcome!'; for (let cnt = 0; cnt < membersAdded.length; ++cnt) { if (membersAdded[cnt].id !== context.activity.recipient.id) { diff --git a/samples/javascript_nodejs/49.echo-proxy-bot/index.js b/samples/javascript_nodejs/49.echo-proxy-bot/index.js index 530bed3a26..9ab81c79c2 100644 --- a/samples/javascript_nodejs/49.echo-proxy-bot/index.js +++ b/samples/javascript_nodejs/49.echo-proxy-bot/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const path = require('path'); const dotenv = require('dotenv'); @@ -34,8 +36,8 @@ server.listen(process.env.port || process.env.PORT || 3978, () => { const proxy = require('node-global-proxy').default; proxy.setConfig({ - http: process.env.HTTP_PROXY, - https: process.env.HTTPS_PROXY + http: process.env.HTTP_PROXY ?? '', + https: process.env.HTTPS_PROXY ?? '' }); proxy.start(); diff --git a/samples/javascript_nodejs/80.skills-simple-bot-to-bot/echo-skill-bot/bot.js b/samples/javascript_nodejs/80.skills-simple-bot-to-bot/echo-skill-bot/bot.js index d379a4378d..4ad00ce004 100644 --- a/samples/javascript_nodejs/80.skills-simple-bot-to-bot/echo-skill-bot/bot.js +++ b/samples/javascript_nodejs/80.skills-simple-bot-to-bot/echo-skill-bot/bot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler, ActivityTypes, EndOfConversationCodes } = require('botbuilder'); class EchoBot extends ActivityHandler { diff --git a/samples/javascript_nodejs/80.skills-simple-bot-to-bot/echo-skill-bot/index.js b/samples/javascript_nodejs/80.skills-simple-bot-to-bot/echo-skill-bot/index.js index 57c46569b1..d392999d08 100644 --- a/samples/javascript_nodejs/80.skills-simple-bot-to-bot/echo-skill-bot/index.js +++ b/samples/javascript_nodejs/80.skills-simple-bot-to-bot/echo-skill-bot/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const dotenv = require('dotenv'); const path = require('path'); const restify = require('restify'); diff --git a/samples/javascript_nodejs/80.skills-simple-bot-to-bot/simple-root-bot/index.js b/samples/javascript_nodejs/80.skills-simple-bot-to-bot/simple-root-bot/index.js index 332f75adc2..782aa71f7f 100644 --- a/samples/javascript_nodejs/80.skills-simple-bot-to-bot/simple-root-bot/index.js +++ b/samples/javascript_nodejs/80.skills-simple-bot-to-bot/simple-root-bot/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + // index.js is used to setup and configure your bot // Import required packages @@ -117,16 +119,18 @@ async function endSkillConversation(context) { // forwarded to a Skill. const activeSkill = await conversationState.createProperty(RootBot.ActiveSkillPropertyName).get(context); if (activeSkill) { - const botId = process.env.MicrosoftAppId; + const botId = process.env.MicrosoftAppId ?? ''; let endOfConversation = { type: ActivityTypes.EndOfConversation, code: 'RootSkillError' }; + // @ts-ignore endOfConversation = TurnContext.applyConversationReference( endOfConversation, TurnContext.getConversationReference(context.activity), true); await conversationState.saveChanges(context, true); + // @ts-ignore await skillClient.postActivity(botId, activeSkill.appId, activeSkill.skillEndpoint, skillsConfig.skillHostEndpoint, endOfConversation.conversation.id, endOfConversation); } } catch (err) { diff --git a/samples/javascript_nodejs/80.skills-simple-bot-to-bot/simple-root-bot/rootBot.js b/samples/javascript_nodejs/80.skills-simple-bot-to-bot/simple-root-bot/rootBot.js index e1b4dd15f1..6880124ec9 100644 --- a/samples/javascript_nodejs/80.skills-simple-bot-to-bot/simple-root-bot/rootBot.js +++ b/samples/javascript_nodejs/80.skills-simple-bot-to-bot/simple-root-bot/rootBot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler, ActivityTypes } = require('botbuilder'); class RootBot extends ActivityHandler { @@ -88,7 +90,7 @@ class RootBot extends ActivityHandler { }); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; for (let cnt = 0; cnt < membersAdded.length; ++cnt) { if (membersAdded[cnt].id !== context.activity.recipient.id) { await context.sendActivity('Hello and welcome!'); diff --git a/samples/javascript_nodejs/80.skills-simple-bot-to-bot/simple-root-bot/skillsConfiguration.js b/samples/javascript_nodejs/80.skills-simple-bot-to-bot/simple-root-bot/skillsConfiguration.js index 3e00d5a173..d079de6e66 100644 --- a/samples/javascript_nodejs/80.skills-simple-bot-to-bot/simple-root-bot/skillsConfiguration.js +++ b/samples/javascript_nodejs/80.skills-simple-bot-to-bot/simple-root-bot/skillsConfiguration.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + /** * A helper class that loads Skills information from configuration. */ diff --git a/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/bots/rootBot.js b/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/bots/rootBot.js index c5d3cdfac2..3f88cc8eec 100644 --- a/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/bots/rootBot.js +++ b/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/bots/rootBot.js @@ -1,15 +1,20 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler, ActivityTypes, CardFactory } = require('botbuilder'); const { runDialog } = require('botbuilder-dialogs'); const WelcomeCard = require('../cards/welcomeCard.json'); +/** @import { ConversationState } from 'botbuilder' */ +/** @import { MainDialog } from '../dialogs/mainDialog' */ + class RootBot extends ActivityHandler { /** * * @param {ConversationState} conversationState - * @param {Dialog} dialog + * @param {MainDialog} dialog */ constructor(conversationState, dialog) { super(); @@ -29,7 +34,7 @@ class RootBot extends ActivityHandler { }); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; for (let cnt = 0; cnt < membersAdded.length; cnt++) { // To learn more about Adaptive Cards, see https://aka.ms/msbot-adaptivecards. if (membersAdded[cnt].id !== context.activity.recipient.id) { diff --git a/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/dialogs/mainDialog.js b/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/dialogs/mainDialog.js index 3c5cdbc2d7..b977c59c87 100644 --- a/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/dialogs/mainDialog.js +++ b/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/dialogs/mainDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityTypes, InputHints, MessageFactory } = require('botbuilder'); const { ChoicePrompt, ComponentDialog, DialogSet, DialogTurnStatus, SkillDialog, WaterfallDialog } = require('botbuilder-dialogs'); @@ -177,11 +179,11 @@ class MainDialog extends ComponentDialog { const skillInfo = skillsConfig.skills[skillId]; const skillOptions = { - botId: process.env.MicrosoftAppId, + botId: process.env.MicrosoftAppId ?? '', conversationIdFactory, conversationState, skill: skillInfo, - skillHostEndpoint: process.env.SkillHostEndpoint, + skillHostEndpoint: process.env.SkillHostEndpoint ?? '', skillClient }; @@ -247,7 +249,9 @@ class MainDialog extends ComponentDialog { value: { latitude: 47.614891, longitude: -122.195801 - } + }, + channelData: {}, + properties: {} }; } diff --git a/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/index.js b/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/index.js index d4fd930598..c4ba09be9c 100644 --- a/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/index.js +++ b/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + // index.js is used to setup and configure your bot. // Import required packages. @@ -121,18 +123,20 @@ async function endSkillConversation(context) { // Inform the active skill that the conversation is ended so that it has a chance to clean up. // Note: the root bot manages the ActiveSkillPropertyName, which has a value while the root bot // has an active conversation with a skill. - const activeSkill = await conversationState.createProperty(mainDialog.ActiveSkillPropertyName).get(context); + const activeSkill = await conversationState.createProperty(mainDialog.activeSkillPropertyName).get(context); if (activeSkill) { - const botId = process.env.MicrosoftAppId; + const botId = process.env.MicrosoftAppId ?? ''; let endOfConversation = { type: ActivityTypes.EndOfConversation, code: 'RootSkillError' }; + // @ts-ignore endOfConversation = TurnContext.applyConversationReference( endOfConversation, TurnContext.getConversationReference(context.activity), true); await conversationState.saveChanges(context, true); + // @ts-ignore await skillClient.postActivity(botId, activeSkill.appId, activeSkill.skillEndpoint, skillsConfig.skillHostEndpoint, endOfConversation.conversation.id, endOfConversation); } } catch (err) { @@ -200,7 +204,6 @@ skillEndpoint.register(server, '/api/skills'); server.on('upgrade', async (req, socket, head) => { // Create an adapter scoped to this WebSocket connection to allow storing session data. const streamingAdapter = new CloudAdapter(botFrameworkAuthentication); - // Set onTurnError for the CloudAdapter created for each connection. streamingAdapter.onTurnError = onTurnErrorHandler; diff --git a/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/middleware/loggerMiddleware.js b/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/middleware/loggerMiddleware.js index 6f1140260a..d7c317754f 100644 --- a/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/middleware/loggerMiddleware.js +++ b/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/middleware/loggerMiddleware.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityTypes } = require('botbuilder'); /** diff --git a/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/skillsConfiguration.js b/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/skillsConfiguration.js index 4490ccac24..32697f31d6 100644 --- a/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/skillsConfiguration.js +++ b/samples/javascript_nodejs/81.skills-skilldialog/dialogRootBot/skillsConfiguration.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + class SkillsConfiguration { constructor() { this.skillsData = {}; diff --git a/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/bots/skillBot.js b/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/bots/skillBot.js index 4e4579c48d..ad3af378be 100644 --- a/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/bots/skillBot.js +++ b/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/bots/skillBot.js @@ -1,14 +1,19 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler } = require('botbuilder'); const { runDialog } = require('botbuilder-dialogs'); +/** @import { ConversationState } from 'botbuilder' */ +/** @import { ActivityRouterDialog } from '../dialogs/activityRouterDialog' */ + class SkillBot extends ActivityHandler { /** * * @param {ConversationState} conversationState - * @param {Dialog} dialog + * @param {ActivityRouterDialog} dialog */ constructor(conversationState, dialog) { super(); diff --git a/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/activityRouterDialog.js b/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/activityRouterDialog.js index 052b1016a4..579ad20038 100644 --- a/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/activityRouterDialog.js +++ b/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/activityRouterDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityTypes, InputHints } = require('botbuilder'); const { ComponentDialog, DialogTurnStatus, WaterfallDialog } = require('botbuilder-dialogs'); const { LuisRecognizer } = require('botbuilder-ai'); @@ -14,7 +16,7 @@ const BOOKING_DIALOG = 'bookingDialog'; * A root dialog that can route activities sent to the skill to different sub-dialogs. */ class ActivityRouterDialog extends ComponentDialog { - constructor(conversationState, luisRecognizer = undefined) { + constructor(conversationState, luisRecognizer) { super(ACTIVITY_ROUTER_DIALOG); if (!conversationState) throw new Error('[MainDialog]: Missing parameter \'conversationState\' is required'); @@ -118,14 +120,14 @@ class ActivityRouterDialog extends ComponentDialog { await stepContext.context.sendActivity(resultString, undefined, InputHints.IgnoringInput); - switch (topIntent.intent) { + switch (topIntent) { case 'BookFlight': return await this.beginBookFlight(stepContext); case 'GetWeather': return await this.beginGetWeather(stepContext); default: { // Catch all for unhandled intents. - const didntUnderstandMessageText = `Sorry, I didn't get that. Please try asking in a different way (intent was ${ topIntent.intent })`; + const didntUnderstandMessageText = `Sorry, I didn't get that. Please try asking in a different way (intent was ${ topIntent })`; await stepContext.context.sendActivity(didntUnderstandMessageText, didntUnderstandMessageText, InputHints.IgnoringInput); break; } @@ -151,7 +153,7 @@ class ActivityRouterDialog extends ComponentDialog { // Start the booking dialog. const bookingDialog = this.findDialog(BOOKING_DIALOG); - return await stepContext.beginDialog(bookingDialog.id, bookingDetails); + return await stepContext.beginDialog(bookingDialog?.id, bookingDetails); } } diff --git a/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/bookingDialog.js b/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/bookingDialog.js index 897ed30add..515d04ba46 100644 --- a/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/bookingDialog.js +++ b/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/bookingDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { TimexProperty } = require('@microsoft/recognizers-text-data-types-timex-expression'); const { InputHints, MessageFactory } = require('botbuilder'); const { ConfirmPrompt, TextPrompt, WaterfallDialog } = require('botbuilder-dialogs'); diff --git a/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/cancelAndHelpDialog.js b/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/cancelAndHelpDialog.js index a390bd1975..f85a8b0937 100644 --- a/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/cancelAndHelpDialog.js +++ b/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/cancelAndHelpDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { InputHints } = require('botbuilder'); const { ComponentDialog, DialogTurnStatus } = require('botbuilder-dialogs'); diff --git a/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/dateResolverDialog.js b/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/dateResolverDialog.js index aaec1e7b44..79ce8f469f 100644 --- a/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/dateResolverDialog.js +++ b/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/dateResolverDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { InputHints, MessageFactory } = require('botbuilder'); const { DateTimePrompt, WaterfallDialog } = require('botbuilder-dialogs'); const { CancelAndHelpDialog } = require('./cancelAndHelpDialog'); diff --git a/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/flightBookingRecognizer.js b/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/flightBookingRecognizer.js index d002d495b5..1fa4b0ecd3 100644 --- a/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/flightBookingRecognizer.js +++ b/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/dialogs/flightBookingRecognizer.js @@ -1,8 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { LuisRecognizer } = require('botbuilder-ai'); +/** @import { TurnContext } from 'botbuilder' */ + class FlightBookingRecognizer { constructor(config) { const luisIsConfigured = config && config.applicationId && config.endpointKey && config.endpoint; @@ -26,7 +30,7 @@ class FlightBookingRecognizer { * @param {TurnContext} context */ async executeLuisQuery(context) { - return await this.recognizer.recognize(context); + return await this.recognizer?.recognize(context); } getFromEntities(result) { diff --git a/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/index.js b/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/index.js index 8862d5d8d5..0b59148b99 100644 --- a/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/index.js +++ b/samples/javascript_nodejs/81.skills-skilldialog/dialogSkillBot/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + // index.js is used to setup and configure your bot. // Import required packages. diff --git a/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/bots/rootBot.js b/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/bots/rootBot.js index cf43ec6673..8c0f8f00de 100644 --- a/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/bots/rootBot.js +++ b/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/bots/rootBot.js @@ -1,14 +1,19 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler, ActivityTypes, MessageFactory } = require('botbuilder'); const { runDialog } = require('botbuilder-dialogs'); +/** @import { ConversationState } from 'botbuilder' */ +/** @import { MainDialog } from '../dialogs/mainDialog' */ + class RootBot extends ActivityHandler { /** * * @param {ConversationState} conversationState - * @param {Dialog} dialog + * @param {MainDialog} dialog */ constructor(conversationState, dialog) { super(); @@ -28,7 +33,7 @@ class RootBot extends ActivityHandler { }); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; for (let cnt = 0; cnt < membersAdded.length; cnt++) { // Greet anyone that was not the target (recipient) of this message. if (membersAdded[cnt].id !== context.activity.recipient.id) { diff --git a/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/dialogs/mainDialog.js b/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/dialogs/mainDialog.js index 0b1aefd584..f9feb17420 100644 --- a/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/dialogs/mainDialog.js +++ b/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/dialogs/mainDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityTypes, InputHints, MessageFactory } = require('botbuilder'); const { ChoicePrompt, ComponentDialog, SkillDialog, WaterfallDialog } = require('botbuilder-dialogs'); const { SsoSignInDialog } = require('./ssoSignInDialog'); diff --git a/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/dialogs/ssoSignInDialog.js b/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/dialogs/ssoSignInDialog.js index 497ad8aad5..22b1780dc9 100644 --- a/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/dialogs/ssoSignInDialog.js +++ b/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/dialogs/ssoSignInDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ComponentDialog, WaterfallDialog, OAuthPrompt } = require('botbuilder-dialogs'); const SSO_SIGNIN_DIALOG = 'SsoSignInDialog'; diff --git a/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/index.js b/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/index.js index 0e0f3ae840..6fba19fa4c 100644 --- a/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/index.js +++ b/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + // index.js is used to setup and configure your bot. // Import required packages. @@ -120,7 +122,7 @@ async function endSkillConversation(context) { // Inform the active skill that the conversation is ended so that it has a chance to clean up. // Note: the root bot manages the ActiveSkillPropertyName, which has a value while the root bot // has an active conversation with a skill. - const activeSkill = await conversationState.createProperty(mainDialog.ActiveSkillPropertyName).get(context); + const activeSkill = await conversationState.createProperty(mainDialog.activeSkillPropertyName).get(context); if (activeSkill) { const botId = process.env.MicrosoftAppId; @@ -128,11 +130,13 @@ async function endSkillConversation(context) { type: ActivityTypes.EndOfConversation, code: 'RootSkillError' }; + // @ts-ignore endOfConversation = TurnContext.applyConversationReference( endOfConversation, TurnContext.getConversationReference(context.activity), true); await conversationState.saveChanges(context, true); skillClient.createBotFrameworkClient(); + // @ts-ignore await skillClient.postActivity(botId, activeSkill.appId, activeSkill.skillEndpoint, skillsConfig.skillHostEndpoint, endOfConversation.conversation.id, endOfConversation); } } catch (err) { diff --git a/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/middleware/loggerMiddleware.js b/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/middleware/loggerMiddleware.js index 6f1140260a..d7c317754f 100644 --- a/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/middleware/loggerMiddleware.js +++ b/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/middleware/loggerMiddleware.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityTypes } = require('botbuilder'); /** diff --git a/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/skillsConfiguration.js b/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/skillsConfiguration.js index 3e00d5a173..d079de6e66 100644 --- a/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/skillsConfiguration.js +++ b/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/skillsConfiguration.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + /** * A helper class that loads Skills information from configuration. */ diff --git a/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/tokenExchangeSkillHandler.js b/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/tokenExchangeSkillHandler.js index 9f0dfa1182..09c7bbfa75 100644 --- a/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/tokenExchangeSkillHandler.js +++ b/samples/javascript_nodejs/82.skills-sso-cloudadapter/rootBot/tokenExchangeSkillHandler.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityEx, ActivityTypes, CardFactory, CloudSkillHandler, tokenExchangeOperationName, TurnContext } = require('botbuilder'); const { JwtTokenValidation } = require('botframework-connector'); const { v4 } = require('uuid'); @@ -17,7 +19,7 @@ class TokenExchangeSkillHandler extends CloudSkillHandler { if (!skillsConfiguration) throw new Error('[TokenExchangeSkillHandler]: Missing parameter \'skillsConfiguration\' is required'); this.adapter = adapter; - this.auth = auth; + this.authorization = auth; this.conversationIdFactory = conversationIdFactory; this.skillsConfig = skillsConfiguration; @@ -57,7 +59,7 @@ class TokenExchangeSkillHandler extends CloudSkillHandler { const oauthCard = oauthCardAttachment.content; if (oauthCard && oauthCard.tokenExchangeResource && oauthCard.tokenExchangeResource.uri) { - const tokenClient = await this.auth.createUserTokenClient(claimsIdentity); + const tokenClient = await this.authorization.createUserTokenClient(claimsIdentity); const context = new TurnContext(this.adapter, activity); context.turnState.push('BotIdentity', claimsIdentity); @@ -96,7 +98,7 @@ class TokenExchangeSkillHandler extends CloudSkillHandler { activity.serviceUrl = skillConversationReference.conversationReference.serviceUrl; // Route the activity to the skill - const botFrameworkClient = this.auth.createBotFrameworkClient(); + const botFrameworkClient = this.authorization.createBotFrameworkClient(); const response = await botFrameworkClient.postActivity(this.botId, targetSkill.appId, targetSkill.skillEndpoint, this.skillsConfig.skillHostEndpoint, activity.conversation.id, activity); // Check response status: true if success, false if failure diff --git a/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/bots/skillBot.js b/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/bots/skillBot.js index 4e4579c48d..ad3af378be 100644 --- a/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/bots/skillBot.js +++ b/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/bots/skillBot.js @@ -1,14 +1,19 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler } = require('botbuilder'); const { runDialog } = require('botbuilder-dialogs'); +/** @import { ConversationState } from 'botbuilder' */ +/** @import { ActivityRouterDialog } from '../dialogs/activityRouterDialog' */ + class SkillBot extends ActivityHandler { /** * * @param {ConversationState} conversationState - * @param {Dialog} dialog + * @param {ActivityRouterDialog} dialog */ constructor(conversationState, dialog) { super(); diff --git a/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/dialogs/activityRouterDialog.js b/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/dialogs/activityRouterDialog.js index 0a71019428..565e0b3743 100644 --- a/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/dialogs/activityRouterDialog.js +++ b/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/dialogs/activityRouterDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityTypes, InputHints, MessageFactory } = require('botbuilder'); const { ComponentDialog, DialogTurnStatus, WaterfallDialog } = require('botbuilder-dialogs'); const { SsoSkillDialog } = require('./ssoSkillDialog'); @@ -16,7 +18,7 @@ class ActivityRouterDialog extends ComponentDialog { constructor() { super(ACTIVITY_ROUTER_DIALOG); - this.addDialog(new SsoSkillDialog(process.env.ConnectionName)) + this.addDialog(new SsoSkillDialog(process.env.ConnectionName ?? '')) .addDialog(new WaterfallDialog(WATERFALL_DIALOG, [ this.processActivity.bind(this) ])); diff --git a/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/dialogs/ssoSkillDialog.js b/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/dialogs/ssoSkillDialog.js index 87141ad502..08458dae9d 100644 --- a/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/dialogs/ssoSkillDialog.js +++ b/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/dialogs/ssoSkillDialog.js @@ -1,10 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { MessageFactory, InputHints } = require('botbuilder'); const { ComponentDialog, ChoicePrompt, ChoiceFactory, DialogTurnStatus, WaterfallDialog } = require('botbuilder-dialogs'); const { SsoSkillSignInDialog } = require('./ssoSkillSignInDialog'); +/** @import { WaterfallStepContext } from 'botbuilder-dialogs' */ + const ACTION_PROMPT = 'ActionStepPrompt'; const WATERFALL_DIALOG = 'WaterfallDialog'; const SSO_SKILL_DIALOG = 'SsoSkillDialog'; @@ -32,7 +36,7 @@ class SsoSkillDialog extends ComponentDialog { } /** - * @param {import('botbuilder-dialogs').WaterfallStepContext} stepContext + * @param {WaterfallStepContext} stepContext */ async promptActionStep(stepContext) { const messageText = 'What SSO action would you like to perform on the skill?'; @@ -46,11 +50,12 @@ class SsoSkillDialog extends ComponentDialog { } /** - * @param {import('botbuilder-dialogs').WaterfallStepContext} stepContext + * @param {WaterfallStepContext} stepContext */ async getPromptChoices(stepContext) { // Try to get the token for the current user to determine if it is logged in or not. const choices = new Set(); + // @ts-ignore const userTokenClient = stepContext.context.turnState.get(stepContext.context.adapter.UserTokenClientKey); const tokenResponse = await userTokenClient.getUserToken( stepContext.context.activity.from.id, @@ -73,10 +78,11 @@ class SsoSkillDialog extends ComponentDialog { } /** - * @param {import('botbuilder-dialogs').WaterfallStepContext} stepContext + * @param {WaterfallStepContext} stepContext */ async handleActionStep(stepContext) { const action = stepContext.result.value.toLowerCase(); + // @ts-ignore const userTokenClient = stepContext.context.turnState.get(stepContext.context.adapter.UserTokenClientKey); switch (action) { @@ -119,7 +125,7 @@ class SsoSkillDialog extends ComponentDialog { } /** - * @param {import('botbuilder-dialogs').WaterfallStepContext} stepContext + * @param {WaterfallStepContext} stepContext */ async promptFinalStep(stepContext) { // Restart the dialog (we will exit when the user says end). diff --git a/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/dialogs/ssoSkillSignInDialog.js b/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/dialogs/ssoSkillSignInDialog.js index 8d9677b9e9..c8836154c4 100644 --- a/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/dialogs/ssoSkillSignInDialog.js +++ b/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/dialogs/ssoSkillSignInDialog.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ComponentDialog, OAuthPrompt, WaterfallDialog } = require('botbuilder-dialogs'); const OAUTH_PROMPT = 'OAuthPrompt'; diff --git a/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/index.js b/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/index.js index 94a1a2b9ac..2f24d43891 100644 --- a/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/index.js +++ b/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + // index.js is used to setup and configure your bot. // Import required packages. diff --git a/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/middleware/ssoSaveStateMiddleware.js b/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/middleware/ssoSaveStateMiddleware.js index 06f1a66d82..50f4c2559d 100644 --- a/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/middleware/ssoSaveStateMiddleware.js +++ b/samples/javascript_nodejs/82.skills-sso-cloudadapter/skillBot/middleware/ssoSaveStateMiddleware.js @@ -1,18 +1,22 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { CardFactory } = require('botbuilder'); +/** @import { Activity, ConversationState, TurnContext } from 'botbuilder' */ + class SsoSaveStateMiddleware { /** - * @param {import('botbuilder').ConversationState} conversationState + * @param {ConversationState} conversationState */ constructor(conversationState) { this.conversationState = conversationState; } /** - * @param {import('botbuilder').TurnContext} turnContext + * @param {TurnContext} turnContext */ async onTurn(turnContext, next) { // Register outgoing handler. @@ -23,8 +27,8 @@ class SsoSaveStateMiddleware { } /** - * @param {import('botbuilder').TurnContext} turnContext - * @param {Partial[]} activities + * @param {TurnContext} turnContext + * @param {Partial[]} activities * @param {Function} next */ async outgoingHandler(turnContext, activities, next) { diff --git a/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/bot.js b/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/bot.js index ae74edc973..637183523b 100644 --- a/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/bot.js +++ b/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/bot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler, MessageFactory } = require('botbuilder'); class NamedPipeBot extends ActivityHandler { @@ -15,7 +17,7 @@ class NamedPipeBot extends ActivityHandler { }); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; const welcomeText = 'Hello and welcome!'; for (let cnt = 0; cnt < membersAdded.length; ++cnt) { if (membersAdded[cnt].id !== context.activity.recipient.id) { diff --git a/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/index.js b/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/index.js index 76006bd321..40d4d11184 100644 --- a/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/index.js +++ b/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const path = require('path'); const dotenv = require('dotenv'); @@ -46,7 +48,7 @@ adapter.connectNamedPipe( async (context) => { await myBot.run(context); }, - process.env.MicrosoftAppId, + process.env.MicrosoftAppId ?? '', AuthenticationConstants.ToChannelFromBotOAuthScope); // Catch-all for errors. @@ -122,10 +124,10 @@ server.post('/api/token/directlinease', async (req, res) => { console.log('Refreshing Direct Line ASE token'); } else { console.log( - `Requesting Direct Line ASE token using secret "${ DIRECT_LINE_SECRET.substring( + `Requesting Direct Line ASE token using secret "${ DIRECT_LINE_SECRET?.substring( 0, 3 - ) }...${ DIRECT_LINE_SECRET.substring(-3) }"` + ) }...${ DIRECT_LINE_SECRET?.substring(-3) }"` ); } } catch (err) { diff --git a/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/utils/createUserId.js b/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/utils/createUserId.js index 5479a16a86..2c4c7848d5 100644 --- a/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/utils/createUserId.js +++ b/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/utils/createUserId.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const random = require('math-random'); module.exports = function createUserID() { diff --git a/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/utils/generateDirectLineToken.js b/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/utils/generateDirectLineToken.js index 18efe089f3..2ac06f3830 100644 --- a/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/utils/generateDirectLineToken.js +++ b/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/utils/generateDirectLineToken.js @@ -1,11 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const createUserId = require('./createUserId'); -const fetch = require('cross-fetch'); +const fetch = require('cross-fetch').default; module.exports = async function( - directLineSecret = process.env.DIRECT_LINE_SECRET, + directLineSecret = process.env.DIRECT_LINE_SECRET ?? '', { domain = process.env.WEBSITE_HOSTNAME, userId = createUserId() } = {} ) { console.log( diff --git a/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/utils/renewDirectLineToken.js b/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/utils/renewDirectLineToken.js index e98ba16fa9..40fd2eb3c7 100644 --- a/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/utils/renewDirectLineToken.js +++ b/samples/javascript_nodejs/83.named-pipe-sample/named-pipe-bot/utils/renewDirectLineToken.js @@ -1,7 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -const fetch = require('cross-fetch'); +// @ts-check + +const fetch = require('cross-fetch').default; +const path = require('path'); +const dotenv = require('dotenv'); + +const ENV_FILE = path.join(__dirname, '..', '.env'); +dotenv.config({ path: ENV_FILE }); module.exports = async function( token, diff --git a/samples/javascript_nodejs/84.bot-authentication-certificate/authBot.js b/samples/javascript_nodejs/84.bot-authentication-certificate/authBot.js index 657637efae..d99b42cd51 100644 --- a/samples/javascript_nodejs/84.bot-authentication-certificate/authBot.js +++ b/samples/javascript_nodejs/84.bot-authentication-certificate/authBot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler, MessageFactory } = require('botbuilder'); class AuthBot extends ActivityHandler { @@ -16,7 +18,7 @@ class AuthBot extends ActivityHandler { }); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; const welcomeText = 'Welcome to Authentication Bot with SSL/TLS Certificate.'; for (let cnt = 0; cnt < membersAdded.length; ++cnt) { if (membersAdded[cnt].id !== context.activity.recipient.id) { diff --git a/samples/javascript_nodejs/84.bot-authentication-certificate/index.js b/samples/javascript_nodejs/84.bot-authentication-certificate/index.js index 3d488f9515..97454e5c5a 100644 --- a/samples/javascript_nodejs/84.bot-authentication-certificate/index.js +++ b/samples/javascript_nodejs/84.bot-authentication-certificate/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const path = require('path'); // const fs = require('fs'); const dotenv = require('dotenv'); @@ -41,7 +43,7 @@ const { AuthBot } = require('./authBot'); const vaultName = process.env.KeyVaultName; const keyVaultUrl = `https://${ vaultName }.vault.azure.net`; - const certificateName = process.env.CertificateName; + const certificateName = process.env.CertificateName ?? ''; // Using an Azure credential object and a keyVaultUrl, let's create a SecretClient const secretClient = new SecretClient(keyVaultUrl, credential); diff --git a/samples/javascript_nodejs/85.bot-authentication-sni/authBot.js b/samples/javascript_nodejs/85.bot-authentication-sni/authBot.js index ba368c382e..02307376be 100644 --- a/samples/javascript_nodejs/85.bot-authentication-sni/authBot.js +++ b/samples/javascript_nodejs/85.bot-authentication-sni/authBot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler, MessageFactory } = require('botbuilder'); class AuthBot extends ActivityHandler { @@ -16,7 +18,7 @@ class AuthBot extends ActivityHandler { }); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; const welcomeText = 'Welcome to the Bot with Subject Name/Issuer Authentication'; for (let cnt = 0; cnt < membersAdded.length; ++cnt) { if (membersAdded[cnt].id !== context.activity.recipient.id) { diff --git a/samples/javascript_nodejs/85.bot-authentication-sni/index.js b/samples/javascript_nodejs/85.bot-authentication-sni/index.js index a0c5837064..9a34b3c6be 100644 --- a/samples/javascript_nodejs/85.bot-authentication-sni/index.js +++ b/samples/javascript_nodejs/85.bot-authentication-sni/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const path = require('path'); // const fs = require('fs'); const { createPrivateKey } = require('crypto'); @@ -50,14 +52,14 @@ const { AuthBot } = require('./authBot'); const vaultName = process.env.KeyVaultName; const keyVaultUrl = `https://${ vaultName }.vault.azure.net`; - const certificateName = process.env.CertificateName; + const certificateName = process.env.CertificateName ?? ''; // Using an Azure credential object and a keyVaultUrl, let's create a SecretClient. const secretClient = new SecretClient(keyVaultUrl, credential); // Assuming you've already created a Key Vault certificate, // and that certificateName contains the name of your certificate. - const cert = (await secretClient.getSecret(certificateName)).value; + const cert = (await secretClient.getSecret(certificateName)).value ?? ''; // ---- Authenticate using local certificate. // //Read the certificate from the file @@ -73,9 +75,9 @@ const { AuthBot } = require('./authBot'); // Create client credentials using SNI authentication from MSAL. const serviceClientCredentialsFactory = new CertificateServiceClientCredentialsFactory( - process.env.MicrosoftAppId, + process.env.MicrosoftAppId ?? '', cert, - privateKey, + privateKey.toString(), process.env.MicrosoftAppTenantId ); diff --git a/samples/javascript_nodejs/86.bot-authentication-fic/bot.js b/samples/javascript_nodejs/86.bot-authentication-fic/bot.js index f1a5a2428c..25f399c1fb 100644 --- a/samples/javascript_nodejs/86.bot-authentication-fic/bot.js +++ b/samples/javascript_nodejs/86.bot-authentication-fic/bot.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const { ActivityHandler, MessageFactory } = require('botbuilder'); class EchoBot extends ActivityHandler { @@ -16,7 +18,7 @@ class EchoBot extends ActivityHandler { }); this.onMembersAdded(async (context, next) => { - const membersAdded = context.activity.membersAdded; + const membersAdded = context.activity.membersAdded ?? []; const welcomeText = 'Hello and welcome to Echo Bot Using Federated Identity Credentials !!'; for (let cnt = 0; cnt < membersAdded.length; ++cnt) { if (membersAdded[cnt].id !== context.activity.recipient.id) { diff --git a/samples/javascript_nodejs/86.bot-authentication-fic/index.js b/samples/javascript_nodejs/86.bot-authentication-fic/index.js index 4461fd31da..2d51782ace 100644 --- a/samples/javascript_nodejs/86.bot-authentication-fic/index.js +++ b/samples/javascript_nodejs/86.bot-authentication-fic/index.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// @ts-check + const path = require('path'); const dotenv = require('dotenv'); const restify = require('restify'); @@ -34,8 +36,8 @@ const { EchoBot } = require('./bot'); // Create the Federated Service Client Credentials to be used as the ServiceClientCredentials for the Bot Framework SDK. const serviceClientCredentialsFactory = new FederatedServiceClientCredentialsFactory( - process.env.MicrosoftAppId, - process.env.MicrosoftAppClientId, + process.env.MicrosoftAppId ?? '', + process.env.MicrosoftAppClientId ?? '', process.env.MicrosoftAppTenantId );