Automate RFPs and Security Questionnaires

In this example, we'll review the steps to automatically fill out a security questionnaire or RFP using the Answer API. This example assumes you have a security questionnaire or RFP in a Google Sheet.

Step 1: Create Bot

  • Create a new bot called "RFP Responder" and grant it access to the appropriate knowledge sources. This could be a specific Google Drive folder where you have stored previously completed RFPs or questionnaires, your product wiki, or the help center.

  • Add Instructions about anything you want the bot to know when responding to the questions. For instance: Your job is respond to questions from an RFP by one of our propsects. Follow all best practices for completing RFPs when responding. Just say "I don't know" if you don't know the answer. Use plaintext in your response, no markdown/HTML/rich text.

  • Open the bot modal again and click the "Copy Bot ID" button on the top right. This will be used to make the API requests in Step 3.

Step 2: Get API Key

  • Create a new API token from here or get an existing one. This will also be used to make the API requests.

Step 3: Paste Apps Script

  • Open the spreadsheet and click on Extensions -> Apps Script from the toolbar.

  • Paste the script below in the Apps Script and add the BOT_ID from Step 1 in Row 34 and API_KEY from Step 2 in Row 30. If necessary, update the sheet name in Row 4, the questions column in Row 7, and the answer column in Row 19.

  • That's it, click "Run" to start! Dashworks will go over each question one by one and add an answer to the spreadsheet.

// Function to loop through questions and call the API
function processQuestions() {
  // Open the spreadsheet and get the sheet by name
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
  
  // Get all the questions from column A (assuming questions are in column A)
  var questions = sheet.getRange('A2:A').getValues(); // Adjust range as needed
  
  // Loop through each question
  for (var i = 0; i < questions.length; i++) {
    var question = questions[i][0];
    
    // Skip empty rows
    if (question) {
      // Call the API and get the answer
      var answer = callApi(question);
      
      // Write the answer to column B (next to the question)
      sheet.getRange(i + 2, 2).setValue(answer); // Adjust row/column as needed
      
      // Wait for 1 minute for rate limits (60,000 milliseconds)
      Utilities.sleep(60000);
    }
  }
}

// Function to call the API
function callApi(question) {
  var url = 'https://api.dashworks.ai/v1/answer'; // API endpoint
  var token = 'API_KEY'; // Replace with your actual token
  
  var payload = {
    'message': question, // The question from the sheet
    'bot_id': 'BOT_ID' // Replace with your actual bot_id
  };
  
  var options = {
    'method': 'post',
    'contentType': 'application/json',
    'headers': {
      'authorization': 'Bearer ' + token, // Authorization token
      'Content-Type': 'application/json'
    },
    'payload': JSON.stringify(payload)
  };
  
  try {
    // Make the API request
    var response = UrlFetchApp.fetch(url, options);
    
    // Parse the response and return the answer
    var json = JSON.parse(response.getContentText());
    return json.answer; // Adjust based on your API response structure
  } catch (error) {
    Logger.log('Error fetching API: ' + error);
    return 'Error fetching answer'; // Return an error message if the API call fails
  }
}

Last updated