Join the Actions on Google Developer Challenge to win a trip to Google I/O 2018 and more than 20 other prizes.

Local fulfillment testing with ngrok

During development, it might be more convenient to use a local web server on your development machine to host fulfillment. However, for fulfillment to work, you need to have a HTTPS URL that is publicly accessible.

Ngrok is a tool that opens a secure tunnel to a local web server and then exposes that to the internet. This allows your actions to properly address your fulfillment host, even though it's being served locally.

Set up and run ngrok

  1. Download ngrok and unpack the zip file to any directory. We'll refer to this as <ngrok-dir>.
  2. Deploy your fulfillment app to a local webhost.
  3. Start ngrok:

    <ngrok-dir>/ngrok http 8080
    

After ngrok launches, it displays the forwarding URL for your local web server (for example, https://xxxxxx.ngrok.io). You'll use this hostname for your fulfillment

Test the action

Now that your fulfillment and ngrok are properly configured, you can test your action.

Actions SDK

  1. Edit the action.json file and change the endpoint URL to the HTTPS forwarding URL provided by ngrok:

    "httpExecution": {
       "url": "https://xxxxxx.ngrok.io"
     }
    
  2. Preview the action using the gactions tool:

    ./gactions preview --action_package action.json --invocation_name "hello action" --preview_mins 1234
    
  3. Test your action with the simulator by running the following command:

    ./gactions simulate
    
  4. Invoke the action:

    talk to hello action
    

API.AI

  1. In the left navigation of API.AI, click Fulfillment and specify the ngrok HTTPS URL (https://xxxxxx.ngrok.io) in the URL field.
  2. Preview the action in the Actions on Google integration screen, as described in Previewing and Testing Actions.

Debugging

The ngrok console displays every incoming HTTP request. You can also inspect the traffic going to http://localhost:4040.

The console for running your action can display any logging in your fulfillment code as well. Make sure you enable debugging for the Actions on Google client library debugging to see the logs:

    process.env.DEBUG = 'actions-on-google:*';