text: // Copyright (c) Microsoft Corporation. All rights reserved.
  // Licensed under the MIT License.
  
  <<<<<<< HEAD
  const { ActivityTypes, TurnContext } = require('botbuilder');
  const { QnAMaker, QnAMakerEndpoint, QnAMakerOptions } = require('botbuilder-ai');
  =======
  const { ActivityTypes } = require('botbuilder');
  const { QnAMaker } = require('botbuilder-ai');
  >>>>>>> 9a1346f23e7379b539e9319c6886e3013dc05145
  
  /**
   * 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.
   */
  class QnAMakerBot {
      /**
       * The QnAMakerBot constructor requires one argument (`endpoint`) which is used to create an instance of `QnAMaker`.
       * @param {QnAMakerEndpoint} endpoint The basic configuration needed to call QnA Maker. In this sample the configuration is retrieved from the .bot file.
       * @param {QnAMakerOptions} config An optional parameter that contains additional settings for configuring a `QnAMaker` when calling the service.
       */
      constructor(endpoint, qnaOptions) {
          this.qnaMaker = new QnAMaker(endpoint, qnaOptions);
      }
  
      /**
       * Every conversation turn for our QnAMakerBot will call this method.
       * There are no dialogs used, since it's "single turn" processing, meaning a single request and
       * response, with no stateful conversation.
       * @param {TurnContext} turnContext A TurnContext instance, containing all the data needed for processing the conversation turn.
       */
      async onTurn(turnContext) {
          // By checking the incoming Activity type, the bot only calls QnA Maker in appropriate cases.
          if (turnContext.activity.type === ActivityTypes.Message) {
              // Perform a call to the QnA Maker service to retrieve matching Question and Answer pairs.
  <<<<<<< HEAD
              const qnaResults = await this.qnaMaker.generateAnswer(turnContext.activity.text);
  =======
              const qnaResults = await this.qnaMaker.getAnswers(turnContext);
  >>>>>>> 9a1346f23e7379b539e9319c6886e3013dc05145
  
              // If an answer was received from QnA Maker, send the answer back to the user.
              if (qnaResults[0]) {
                  await turnContext.sendActivity(qnaResults[0].answer);
  
              // If no answers were returned from QnA Maker, reply with help.
              } else {
                  await turnContext.sendActivity('No QnA Maker answers were found. This example uses a QnA Maker Knowledge Base that focuses on smart light bulbs. To see QnA Maker in action, ask the bot questions like "Why won\'t it turn on?" or "I need help."');
              }
  
          // If the Activity is a ConversationUpdate, send a greeting message to the user.
          } else if (turnContext.activity.type === ActivityTypes.ConversationUpdate &&
                     turnContext.activity.recipient.id !== turnContext.activity.membersAdded[0].id) {
              await turnContext.sendActivity('Welcome to the QnA Maker sample! Ask me a question and I will try to answer it.');
  
          // Respond to all other Activity types.
          } else if (turnContext.activity.type !== ActivityTypes.ConversationUpdate) {
              await turnContext.sendActivity(`[${ turnContext.activity.type }]-type activity detected.`);
          }
      }
  }
  
  module.exports.QnAMakerBot = QnAMakerBot;
  