<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>IFTTT &#8211; BeatificaBytes</title>
	<atom:link href="https://www.BeatificaBytes.be/tag/ifttt/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.BeatificaBytes.be</link>
	<description>The Joys of Computing</description>
	<lastBuildDate>Tue, 25 Sep 2018 21:45:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8</generator>
	<item>
		<title>Call a php webpage from a IFTTT applet using Google Assistant</title>
		<link>https://www.BeatificaBytes.be/call-a-php-webpage-from-a-ifttt-applet-using-google-assistant/</link>
					<comments>https://www.BeatificaBytes.be/call-a-php-webpage-from-a-ifttt-applet-using-google-assistant/#respond</comments>
		
		<dc:creator><![CDATA[vletroye]]></dc:creator>
		<pubDate>Tue, 25 Sep 2018 21:45:46 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Google Assistant]]></category>
		<category><![CDATA[IFTTT]]></category>
		<category><![CDATA[Synology]]></category>
		<guid isPermaLink="false">http://www.BeatificaBytes.be/?p=3871</guid>

					<description><![CDATA[I wanted to be able to wake up PC on my Lan using voice commands. To achieve that, I did implement a solution using Google [&#8230;]]]></description>
										<content:encoded><![CDATA[<p style="text-align: justify">I wanted to be able to wake up PC on my Lan using voice commands. To achieve that, I did implement a solution using Google Assistant, IFTTT and a php web page hosted on my NAS.</p>
<p style="text-align: justify"><span class="collapseomatic " id="id69b6645b940f9"  tabindex="0" title="Click to Read More"    >Click to Read More</span><span id='swap-id69b6645b940f9'  class='colomat-swap' style='display:none;'>Click to Close</span><div id="target-id69b6645b940f9" class="collapseomatic_content ">
<p style="text-align: justify"><strong>Regarding IFTTT, you must have an account. Then,</strong></p>
<ul style="text-align: justify">
<li>Create a new applet,</li>
<li>Choose the service &#8220;Google Assistant&#8221;
<ul>
<li>Choose a trigger, ex.: &#8220;Say a phrase with a text ingredient&#8221;</li>
<li>Type a phrase in &#8220;What do you want to say?&#8221; such as &#8220;Wake up my PC $&#8221; ($ is the symbol to be used for the &#8220;ingredient&#8221;)</li>
<li>Type a phrase in &#8220;What do you want the Assistant to say in response?&#8221; such as &#8220;Ok, I will wake up $&#8221;</li>
</ul>
</li>
<li>Choose next an action service &#8220;Webhooks&#8221; (to &#8220;make a web request&#8221;)
<ul>
<li>Type the url of your web page: http://&lt;public Ip of your NAS&gt;/&lt;some path&gt;/action.php?do=wakeup&amp;param={{TextField}} ({{TextField}} will take the value of the ingredient)</li>
<li>Chose the &#8220;method&#8221;: GET</li>
<li>Chose the &#8220;content type&#8221;: text/plain</li>
</ul>
</li>
</ul>
<p style="text-align: justify"><strong>Regarding the php web page (action.php), I had to do some fine tuning&#8230; So, I started with a page logging all information received from IFTTT:</strong></p>
[php]&lt;/pre&gt;<br />
&lt;?php<br />
// https://gist.github.com/magnetikonline/650e30e485c0f91f2f40<br />
class DumpHTTPRequestToFile<br />
{<br />
public function execute($targetFile)<br />
{<br />
$boby = json_decode(file_get_contents(&#8216;php://input&#8217;) , true);</p>
<p>$data = sprintf(&quot;&lt;h2&gt;&lt;u&gt;IFTTT call at %s on %s&lt;/u&gt;&lt;/h2&gt;&lt;h3&gt;Method:&lt;/h3&gt;&quot;, date(&#8216;h:i:s&#8217;) , date(&#8216;d/m/Y&#8217;));<br />
$data .= sprintf(&quot;&lt;blockquote&gt;%s (%s): %s &lt;/blockquote&gt;&lt;h3&gt;HTTP headers:&lt;/h3&gt;&lt;ul&gt;&quot;, $_SERVER[&#8216;REQUEST_METHOD&#8217;], $_SERVER[&#8216;SERVER_PROTOCOL&#8217;], htmlentities($_SERVER[&#8216;REQUEST_URI&#8217;]));<br />
foreach ($this-&gt;getHeaderList() as $name =&gt; $value)<br />
{<br />
$data .= &quot;&lt;li&gt;&lt;b&gt;&quot; . $name . &#8216;&lt;/b&gt;: &#8216; . $value . &quot;&lt;/li&gt;&quot;;<br />
}</p>
<p>$data .= &quot;&lt;/ul&gt;&lt;h3&gt;Post:&lt;/h3&gt;&lt;ul&gt;&quot;;<br />
foreach ($_POST as $key =&gt; $value) $data .= &quot;&lt;li&gt;&quot; . $key . &#8216;=&#8217; . $value . &#8216;&lt;/li&gt;&#8217;;</p>
<p>$bodyhtml = $this-&gt;jsonToTable($boby);<br />
$data .= &quot;&lt;/ul&gt;&lt;h3&gt;Request body:&lt;/h3&gt;&lt;blockquote&gt;$bodyhtml&lt;/blockquote&gt;&quot;;</p>
<p>$action = trim(strtolower($_GET[&#8216;action&#8217;]));<br />
$action = preg_replace(&#8216;/^ *de +/&#8217;, &#8221;, $action);<br />
$action = preg_replace(&#8216;/^ *d *\&#8217; +/&#8217;, &#8221;, $action);</p>
<p>$param = trim(strtolower($_GET[&#8216;param&#8217;]));<br />
$param = preg_replace(&#8216;/^ *de +/&#8217;, &#8221;, $param);<br />
$param = preg_replace(&#8216;/^ *d *\&#8217; +/&#8217;, &#8221;, $param);</p>
<p>$data .= &quot;&lt;h3&gt;Requested Action:&lt;/h3&gt;&lt;blockquote&gt;$action: $param&lt;/blockquote&gt;&quot;;</p>
<p>similar_text(strtolower($param) , &quot;zeus&quot;, $percent);<br />
$data .= &quot;Zeus: $percent %&lt;br&gt;&quot;;</p>
<p>similar_text(strtolower($param) , &quot;chaos&quot;, $percent);<br />
$data .= &quot;Chaos: $percent %&lt;br&gt;&quot;;</p>
<p>file_put_contents($targetFile, $data . file_get_contents($targetFile) . &quot;\n&quot;);</p>
<p>echo (nl2br($data));<br />
}</p>
<p>private function getHeaderList()<br />
{<br />
$headerList = [];<br />
foreach ($_SERVER as $name =&gt; $value)<br />
{<br />
if (preg_match(&#8216;/^HTTP_/&#8217;, $name))<br />
{<br />
// convert HTTP_HEADER_NAME to Header-Name<br />
$name = strtr(substr($name, 5) , &#8216;_&#8217;, &#8216; &#8216;);<br />
$name = ucwords(strtolower($name));<br />
$name = strtr($name, &#8216; &#8216;, &#8216;-&#8216;);<br />
// add to list<br />
$headerList[$name] = $value;<br />
}<br />
}<br />
return $headerList;<br />
}</p>
<p>private function jsonToTable($data)<br />
{<br />
$table = &quot;&lt;table class=&#8217;json-table&#8217; width=&#8217;100%&#8217;&gt;&quot;;<br />
foreach ($data as $key =&gt; $value)<br />
{<br />
$table .= &quot;&lt;tr valign=&#8217;top&#8217;&gt;&quot;;<br />
if (!is_numeric($key))<br />
{<br />
$table .= &quot;<br />
&lt;td&gt;<br />
&lt;strong&gt;&quot; . $key . &quot;:&lt;/strong&gt;<br />
&lt;/td&gt;<br />
&lt;td&gt;<br />
&quot;;<br />
}<br />
else<br />
{<br />
$table .= &quot;<br />
&lt;td colspan=&#8217;2&#8242;&gt;<br />
&quot;;<br />
}<br />
if (is_object($value) || is_array($value))<br />
{<br />
$table .= jsonToTable($value);<br />
}<br />
else<br />
{<br />
$table .= $value;<br />
}<br />
$table .= &quot;<br />
&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&quot;;<br />
}<br />
$table .= &quot;&lt;/table&gt;&quot;;<br />
return $table;<br />
}<br />
}</p>
<p>(new DumpHTTPRequestToFile)-&gt;execute(&#8216;./action.html&#8217;);</p>
<p>?&gt;<br />
&lt;pre&gt;[/php]
<p style="text-align: justify">The log is stored in a html page &#8220;log.html&#8221;.</p>
<p>Notes:</p>
<ul>
<li>I notice that Google was not good at recognizing the name of my PC (IMO because I use French sentences). So I am using a php command &#8220;similar_text&#8221; to evaluate the &#8220;ingredient&#8221;. But this is really far from effective.</li>
<li>I tried to use a &#8220;POST&#8221; method instead of &#8220;Get&#8221; and a Content Type &#8220;application/json&#8221;, it works. But when I add a Body like {“token”:”mseries”,”command”: “&lt;&lt;&lt;{{TextField}}&gt;&gt;&gt;”, ”test”: “data”}, <span style="color: #ff0000">I don&#8217;t see it received by my php page</span> <img src="https://s.w.org/images/core/emoji/15.1.0/72x72/1f641.png" alt="🙁" class="wp-smiley" style="height: 1em; max-height: 1em;" /></li>
<li>If Google Assistant does not call correcly IFTTT, look at you voice command history to be sure it understood you order: https://myactivity.google.com/myactivity?restrict=vaa&amp;utm_source=help</li>
<li>If Google Assistant understood correctly your command, but IFTTT didn&#8217;t call your web page, look at your IFTTT activity: https://ifttt.com/activity</li>
</ul>
<p><strong>A log for a call using a GET method will look like:</strong></p>
<h2 style="padding-left: 30px"><span style="color: #999999"><u>IFTTT call at 11:32:29 on 25/09/2018</u></span></h2>
<h3 style="padding-left: 30px"><span style="color: #999999">Method: </span><span style="color: #999999">GET (HTTP/1.1): /ifttt/action.php?action=wakeup&amp;param=CARROS</span></h3>
<h3 style="padding-left: 30px"><span style="color: #999999">HTTP headers:</span></h3>
<p style="padding-left: 60px"><span style="color: #999999"><b>X-Newrelic-Transaction</b>: PxQGUlECCwFRBVEEVQAAAlQTGlUDChAHHEAJVA1cAgMKA1gEVFNVUVUHFU1EAQACBV1UBlUTag==</span><br />
<span style="color: #999999"><b>X-Newrelic-Id</b>: VwAOU1RRGwAFUFZUAwQE</span><br />
<span style="color: #999999"><b>Content-Type</b>: text/plain</span><br />
<span style="color: #999999"><b>Content-Length</b>: 74</span><br />
<span style="color: #999999"><b>Connection</b>: close</span><br />
<span style="color: #999999"><b>Host</b>: olympe.letroye.be</span><br />
<span style="color: #999999"><b>X-Real-Port</b>: 55748</span><br />
<span style="color: #999999"><b>X-Port</b>: 80</span><br />
<span style="color: #999999"><b>X-Real-Ip</b>: 54.164.110.125</span><br />
<span style="color: #999999"><b>X-Forwarded-By</b>: 192.168.0.200</span></p>
<h3 style="padding-left: 30px"><span style="color: #999999">Post:</span></h3>
<h3 style="padding-left: 30px"><span style="color: #999999">Request body:</span></h3>
<h3 style="padding-left: 30px"><span style="color: #999999">Requested Action: </span><span style="color: #999999">wakeup: CARROS</span></h3>
<p style="padding-left: 30px"><span style="color: #999999">Zeus: 20 %</span><br />
<span style="color: #999999">Chaos: 72.727272727273 %</span></p>
<p><strong>A log for a call using a POST method with application/json content-type will look like:</strong></p>
<h2 style="padding-left: 30px"><span style="color: #999999"><u>IFTTT call at 11:41:14 on 25/09/2018</u></span></h2>
<h3 style="padding-left: 30px"><span style="color: #999999">Method: </span><span style="color: #999999">POST (HTTP/1.1): /ifttt/action.php?action=wakeup&amp;param=Kaos</span></h3>
<h3 style="padding-left: 30px"><span style="color: #999999">HTTP headers:</span></h3>
<p style="padding-left: 60px"><span style="color: #999999"><b>X-Newrelic-Id</b>: VwAOU1RRGwAFUFZUAwQE</span><br />
<span style="color: #999999"><b>Content-Type</b>: application/json</span><br />
<span style="color: #999999"><b>Content-Length</b>: 77</span><br />
<span style="color: #999999"><b>Connection</b>: close</span><br />
<span style="color: #999999"><b>Host</b>: olympe.letroye.be</span><br />
<span style="color: #999999"><b>X-Real-Port</b>: 59892</span><br />
<span style="color: #999999"><b>X-Port</b>: 80</span><br />
<span style="color: #999999"><b>X-Real-Ip</b>: 54.211.16.53</span><br />
<span style="color: #999999"><b>X-Forwarded-By</b>: 192.168.0.200</span></p>
<h3 style="padding-left: 30px"><span style="color: #999999">Post:</span></h3>
<h3 style="padding-left: 30px"><span style="color: #999999">Request body:</span></h3>
<h3 style="padding-left: 30px"><span style="color: #999999">Requested Action: </span><span style="color: #999999">wakeup: kaos</span></h3>
<p style="padding-left: 30px"><span style="color: #999999">Zeus: 25 %</span><br />
<span style="color: #999999">Chaos: 66.666666666667 %</span></p>
<p style="text-align: justify"></div>
<div class="pvc_clear"></div>
<p id="pvc_stats_3871" class="pvc_stats total_only  " data-element-id="3871" style=""><i class="pvc-stats-icon medium" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" version="1.0" viewBox="0 0 502 315" preserveAspectRatio="xMidYMid meet"><g transform="translate(0,332) scale(0.1,-0.1)" fill="" stroke="none"><path d="M2394 3279 l-29 -30 -3 -207 c-2 -182 0 -211 15 -242 39 -76 157 -76 196 0 15 31 17 60 15 243 l-3 209 -33 29 c-26 23 -41 29 -80 29 -41 0 -53 -5 -78 -31z"/><path d="M3085 3251 c-45 -19 -58 -50 -96 -229 -47 -217 -49 -260 -13 -295 52 -53 146 -42 177 20 16 31 87 366 87 410 0 70 -86 122 -155 94z"/><path d="M1751 3234 c-13 -9 -29 -31 -37 -50 -12 -29 -10 -49 21 -204 19 -94 39 -189 45 -210 14 -50 54 -80 110 -80 34 0 48 6 76 34 21 21 34 44 34 59 0 14 -18 113 -40 219 -37 178 -43 195 -70 221 -36 32 -101 37 -139 11z"/><path d="M1163 3073 c-36 -7 -73 -59 -73 -102 0 -56 133 -378 171 -413 34 -32 83 -37 129 -13 70 36 67 87 -16 290 -86 209 -89 214 -129 231 -35 14 -42 15 -82 7z"/><path d="M3689 3066 c-15 -9 -33 -30 -42 -48 -48 -103 -147 -355 -147 -375 0 -98 131 -148 192 -74 13 15 57 108 97 206 80 196 84 226 37 273 -30 30 -99 39 -137 18z"/><path d="M583 2784 c-38 -19 -67 -74 -58 -113 9 -42 211 -354 242 -373 16 -10 45 -18 66 -18 51 0 107 52 107 100 0 39 -1 41 -124 234 -80 126 -108 162 -133 173 -41 17 -61 16 -100 -3z"/><path d="M4250 2784 c-14 -9 -74 -91 -133 -183 -95 -150 -107 -173 -107 -213 0 -55 33 -94 87 -104 67 -13 90 8 211 198 130 202 137 225 78 284 -27 27 -42 34 -72 34 -22 0 -50 -8 -64 -16z"/><path d="M2275 2693 c-553 -48 -1095 -270 -1585 -649 -135 -104 -459 -423 -483 -476 -23 -49 -22 -139 2 -186 73 -142 361 -457 571 -626 285 -228 642 -407 990 -497 242 -63 336 -73 660 -74 310 0 370 5 595 52 535 111 1045 392 1455 803 122 121 250 273 275 326 19 41 19 137 0 174 -41 79 -309 363 -465 492 -447 370 -946 591 -1479 653 -113 14 -422 18 -536 8z m395 -428 c171 -34 330 -124 456 -258 112 -119 167 -219 211 -378 27 -96 24 -300 -5 -401 -72 -255 -236 -447 -474 -557 -132 -62 -201 -76 -368 -76 -167 0 -236 14 -368 76 -213 98 -373 271 -451 485 -162 444 86 934 547 1084 153 49 292 57 452 25z m909 -232 c222 -123 408 -262 593 -441 76 -74 138 -139 138 -144 0 -16 -233 -242 -330 -319 -155 -123 -309 -223 -461 -299 l-81 -41 32 46 c18 26 49 83 70 128 143 306 141 649 -6 957 -25 52 -61 116 -79 142 l-34 47 45 -20 c26 -10 76 -36 113 -56z m-2057 25 c-40 -58 -105 -190 -130 -263 -110 -324 -59 -707 132 -981 25 -35 42 -64 37 -64 -19 0 -241 119 -326 174 -188 122 -406 314 -532 468 l-58 71 108 103 c185 178 428 349 672 473 66 33 121 60 123 61 2 0 -10 -19 -26 -42z"/><path d="M2375 1950 c-198 -44 -350 -190 -395 -379 -18 -76 -8 -221 19 -290 114 -284 457 -406 731 -260 98 52 188 154 231 260 27 69 37 214 19 290 -38 163 -166 304 -326 360 -67 23 -215 33 -279 19z"/></g></svg></i> <img decoding="async" width="16" height="16" alt="Loading" src="https://www.BeatificaBytes.be/wp-content/plugins/page-views-count/ajax-loader-2x.gif" border=0 /></p>
<div class="pvc_clear"></div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.BeatificaBytes.be/call-a-php-webpage-from-a-ifttt-applet-using-google-assistant/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
