Если кто-нибудь знает, пожалуйста, объясните , как настроить API-интерфейс airtable в лямбда-функции (разработка Alexa). А кто-нибудь знает про , как включить доступ к API в настройках Alexa . Я получаю ответ JSON в почтальоне или в терминале, но когда я запускаю код и проверяю навык Alexa, нет ответа на вопросы и отображается ошибка.
здесь код таблица функций Airtable js код
const request = require('request');
BASE_ID = `##############`;
TABLE_NAME = `##############`;
API_KEY = `##############`;
function getAirtable() {
return new Promise((resolve, reject) => {
request({
url: `https://api.airtable.com/v0/${BASE_ID}/${TABLE_NAME}/?api_key=${API_KEY}`,
json: true
}, (error, response, body) => {
if (!error && response.statusCode === 200) {
resolve(body);
} else
reject("Cannot Reach Questions");
});
});
};
async function testAirTable() {
record = await getAirtable()
console.log(`The first Easy Question is : ${record.records[0].fields.Easy}`);
console.log(`The first Hard Question is : ${record.records[0].fields.Hard}`);
console.log(`The first Answer is : ${record.records[0].fields.Answer}`);
console.log(`There are ${record.records.length} Questions`);
};
testAirTable()
#
вот код индекса. js файл с кодом лямбда-папки
BASE_ID = `###################`;
TABLE_NAME = `###################`;
API_KEY = `###################`;
var bigListofQuestions = {};
const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
},
async handle(handlerInput) {
const attributesManager = handlerInput.attributesManager;
// get attributes
const attributes = await attributesManager.getPersistentAttributes() || {};
// get the number of questions and update, minus 1 for the array at zero
bigListofQuestions = await getAirtable();
attributes.totalQuestions = (Number(bigListofQuestions.records.length) - 1);
console.log(`Total Number of Questions found was ${attributes.totalQuestions}`);
if (attributes.userScore === undefined) {
// setup new user if first time here
attributes.questionAsked = false;
attributes.currentAnswer = "";
attributes.userScore = 0;
attributes.timesAnswered = 0;
attributes.listQuestionsAsked = [];
attributes.questionsRight = 0;
attributes.questionsWrong = 0;
speechText = extMsg.WelcomeMsg;
repromptText = extMsg.WelcomeMsg;
} else {
// else welcome back the user
speechText = `<audio src='https://s3.amazonaws.com/ask-soundlibrary/foley/amzn_sfx_glasses_clink_01.mp3'/> Welcome back. You currently have ${attributes.userScore} points. You can say start a new game to reset your score. <break time='.3s'/> ${extMsg.getRandomShallWeBeginfirst()}`;
repromptText = `Welcome back. ${extMsg.getRandomShallWeBeginfirst()}`;
//reset in case we hard exited
attributes.questionAsked = false;
attributes.timesAnswered = 0;
attributes.listQuestionsAsked = [];
}
attributesManager.setPersistentAttributes(attributes);
await attributesManager.savePersistentAttributes();
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(repromptText)
.getResponse();
},
};
ссылка: https://www.youtube.com/playlist?list=PLmaHDLjegjW_ilnkFGkrq5qF5A3hqgf6N