tomharrigan/voicewp

Setup required for news skill?

gehwissenlos opened this issue · 4 comments

I installed the plugin because of the news skill. Do I need to config this skill or does it work out-of-the-box? I'm asking because I get an 404 error in json: {"code":"rest_no_route","message":"Keine Route für URL und Request-Methode gefunden","data":{"status":404}}
https://www.tsv-bodnegg.de/wp-json/alexawp/v1/skill/news

Hey, it should work out of the box if it's set up correctly in the Amazon developer portal. If you visit the URL directly, a 404 is expected (the URL is set up to work with a GET request rather than a POST request), but I tested out your URL with a GET request and got the same response.

A couple of questions to help diagnose the issue:
What version of PHP is your site running on? (If it's 5.3, there's a fix that I'm working on)
Have you tried re-saving the permalinks? (this can be done from Settings -> Permalinks)
Are you able to view the error logs of your site?

I didn't try to enter it in the developer portal after it didn't work in my browser. If I visit the URL directly this should also be a GET request.

The plugin is not activated anymore, so you can't use the link above anymore.

The site is running 7.0.15 and I tried re-saving the permalinks but didn't work.

You're right, my confusion on the GET/POST request mixup.

Anyway, hitting the URL directly is going to fail because it only accepts requests from Alexa.

If you just want to check that the plugin is creating the endpoints, replace the alexawp_news_request() function in alexawp.php with: https://gist.github.com/tomharrigan/9f515b56dff3865a42945172bc66052c

The above just comments out the validation checks.

On line 126 of the same file, add 'GET' to the methods parameter:
register_rest_route( 'alexawp/v1', '/skill/news', [ 'callback' => [ $this, 'alexawp_news_request' ], 'methods' => [ 'GET', 'POST' ], ] );

The response you should see in browser is {"version":"1.0","response":{"outputSpeech":{"type":"PlainText","text":"Protocol isn't secure. Request isn't from Alexa."},"shouldEndSession":true},"sessionAttributes":[]}

Feel free to reopen. Any progress is specific to your input.