question

newuser-f50b2368-52fc-4634-a022-dc723bbf6e01 avatar image
newuser-f50b2368-52fc-4634-a022-dc723bbf6e01 asked ·

alexa skill http requests

Idk if I have an environment issue or what but i cannot make any type of http request from my alexa skill. From the aws console, i log my error and keep getting all sorts of different errors. Using axios with async/await, i get errors like adapter is undefined and using a raw http request I get errors that protocol is undefined. I'm not sure what I'm doing wrong but here's a snippet in typescript of just a basic get that will not make any api requests...


// imports
import * as http from 'http';

 // handler function
   async handle(input: HandlerInput) {
        const { responseBuilder } = input;
        const responseText = `blahhh`;
        try {
            await httpGet();
            responseBuilder.speak(responseText);
        } catch(error) {
            console.error(error);
        }
        return responseBuilder.getResponse();
    }

// httpGet function
const httpGet = function(data) {
    return new Promise((resolve, reject) => {
        const options = {
            hostname: 'httpbin.org',
            path: '/get',
            method: 'GET',
            port: 80
        }
        const request = http.request(options, (response) => {
            response.setEncoding('utf8');
            let returnData = '';
            response.on('data', (chunk) => {
              returnData += chunk;
            });
            response.on('end', () => {
              resolve(JSON.parse(returnData));
            });
            response.on('error', (error) => {
              reject(error);
            });
          });
          request.end();
      });
}


alexa skills kitlambdaaws
1 comment
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I was bundling my index file via webpack and didn't set the target in webpack.config to node, so it didn't include the necessary dependencies.

0 Likes 0 ·

0 Answers