CakePHP APIs and Voice Commands | CakePHP blog
For this project you’ll need Google Assistant either enabled on your phone, or in miniature speaker form.
First we’ll set up an API to accept our request, then we’ll use IFTTT to create a command on our Google Assistant.
Setting up an API
Creating The Skeleton
First we’ll create our project skeleton, then we’ll add the CakeDC/Api. For this part we’ll be following pretty closely to CakeDC’s How to Take a Rest in Five Minutes.
composer create-project --prefer-dist --no-interaction cakephp/app:"~4.0" voiceToCode cd voiceToCode composer config minimum-stability dev
composer require cakedc/cakephp-api:~8.0
Once the plugin is installed we’ll also want to set the Auth bypass since we’ll only be running this locally we shouldn’t have too many bad actors trying to fill your hard drive with nonsense projects.
cp vendor/cakedc/cakephp-api/config/api_permissions.php.default ./config/api_permissions.php bin/cake plugin load CakeDC/Api
Adding our project builder
Now that we’ve created our skeleton all we need to do is create our application SQL structure, then include our application creation code.
Creating the SQL structure. I only want to capture the names of the apps I create, and when I created them, but you can add whatever other information you might need.
CREATE TABLE apps (
id int(10),
name text,
created DATETIME NOT NULL DEFAULT GETDATE(),
);
Then run cake bake to create your controllers
php bin/cake.php bake all apps
Now add the following into the add function
public function add($name) {
//...
exec('php composer.phar create-project --prefer-dist cakephp/app:4.* '. $name);
//...
}
Creating Voice Command
We’ll create a new Google Assistant voice command using IFTTT.
Open IFTTT, and create a new applet
Then add a new Google Assistant command
Then we’ll use webhooks to call our API
As you can see we can now add the ingredient from when we created the Google Assistant command allowing us to specify the name of our newly created application.
Conclusion
That’s all you need to utilize Google Assistant to create brand new apps with your voice!
What do you think of this post, did I miss something, or do you just want to ask a question? Leave a comment down below, and don’t forget to subscribe for future cool projects like the upcoming How to Create a Video Streamer with CakePHP part 2!
Originally published at https://cakephp.blog on October 21, 2020.