rivescript with mysql|angelz1702|fabrice@telecom4all.be|1350915838|angelz1702|xx|0|91.178.160.87|hello,<br /><br />still me :)<br />this time I try to connect rives script to a mysql database<br />the perl code work fine (in perl console)<br />but in rivescript dosn't works <br /><br />can you help me to &quot;transform&quot; this perl code in rivescript code ?<br /><br />[code]<br /><br />+ [*] disjoncteur * [*]<br />- disjoncteur &lt;star1&gt;&lt;call&gt;documentation &lt;star1&gt; &lt;/call&gt;<br /><br /><br />&gt; object documentation perl<br /><br /><br />use DBI;<br />use CGI;<br /><br />$co = new CGI;<br />print $co-&gt;header;<br /><br />$database=&quot;database&quot;;<br />$hostname=&quot;localhost&quot;;<br />$login = &quot;login&quot;;<br />$mdp = &quot;pass&quot;;<br /><br />$dsn = &quot;DBI:mysql:database=$database;host=$hostname&quot;;<br />$dbh = DBI-&gt;connect($dsn, $login, $mdp) or die &quot;Echec connexion&quot;;<br /><br />$requete = &quot;SELECT * FROM my_table &quot;;<br />$sth = $dbh-&gt;prepare($requete);<br /><br />$sth-&gt;execute();<br /><br /><br />while(my @row = $sth-&gt;fetchrow_array)&#123;<br />print $row['0'].&quot; &quot;.$row['1'].&quot; &quot;.$row['2'].&quot; &quot;.$row['3'].&quot; \n&quot;;<br /><br />&#125;<br /><br />$sth -&gt; finish;<br />$dbh -&gt; disconnect;<br /><br /><br />&lt; object<br /><br /><br />[/code]<br /><br />thanks for you help :)<br />||||
Re: rivescript with mysql|Kirsle|casey@cuvou.net|1350923285|Kirsle|xx|0|38.122.20.226|So, the thing to know about Perl being run as CGI is that what Perl prints to its standard output is what gets sent to the web browser, including HTTP headers. In your RiveScript code, you shouldn't be printing anything at all; this should happen a level higher. RiveScript objects should [i]return[/i] their response, not print it.<br /><br />So, your main CGI script could look like this:<br /><br />[code]#!/usr/bin/perl<br /><br />use strict;<br />use RiveScript;<br />use CGI;<br /><br />my $co = new CGI;<br />print $co-&gt;header;<br /><br />my $message = $co-&gt;param(&quot;message&quot;); # get the user's message<br /><br />my $RS = new RiveScript;<br />$RS-&gt;loadDirectory(&quot;./replies&quot;);<br />$RS-&gt;sortReplies();<br /><br />my $reply = $RS-&gt;reply(&quot;cgi_user&quot;, $message);<br />print $reply; # send it to the browser[/code]<br /><br />And in your RiveScript code, instead of printing things out, just add them to a variable and return the variable at the end. You shouldn't need to use the CGI module in your RiveScript code, since this was taken care of by the &quot;parent&quot; CGI script.<br /><br />[quote]+ disjoncteur *<br />- disjoncteur &lt;star1&gt;&lt;call&gt;documentation &lt;star1&gt; &lt;/call&gt;<br /><br /><br />&gt; object documentation perl<br /><br />[color=blue]my $reply;[/color]<br />use DBI;<br /><br />$database=&quot;database&quot;;<br />$hostname=&quot;localhost&quot;;<br />$login = &quot;login&quot;;<br />$mdp = &quot;pass&quot;;<br /><br />$dsn = &quot;DBI:mysql:database=$database;host=$hostname&quot;;<br />$dbh = DBI-&gt;connect($dsn, $login, $mdp) or [color=blue]return &quot;Echec connexion&quot;;[/color]<br /><br />$requete = &quot;SELECT * FROM my_table &quot;;<br />$sth = $dbh-&gt;prepare($requete);<br /><br />$sth-&gt;execute();<br /><br /><br />while(my @row = $sth-&gt;fetchrow_array)&#123;<br />[color=blue]$reply .=[/color] $row['0'].&quot; &quot;.$row['1'].&quot; &quot;.$row['2'].&quot; &quot;.$row['3'].&quot; \n&quot;;<br /><br />&#125;<br /><br />$sth -&gt; finish;<br />$dbh -&gt; disconnect;<br /><br />[color=blue]return $reply;[/color]<br /><br />&lt; object[/quote]<br /><br />I have an extremely simple example of RiveScript being used in a CGI script here: https://github.com/dreamhost/dhbot-2q2012 but note that this bot was &quot;single use&quot; and would need a few changes to the code to be used in production for a high quantity of users. Most notably, that bot saves session data to the hard disk using the current time stamp as the file name, so users who started a conversation within the same second would share the same session, so ideally you'd wanna use MySQL to store session info in.||||
Re: rivescript with mysql|angelz1702|fabrice@telecom4all.be|1350939758|angelz1702|xx|0|91.178.160.87|hello, <br /><br />thanks for reply<br /><br />for the moment I use this script to start bot (with vocal)<br /><br />[code]#!/usr/bin/perl -w<br />use RiveScript;<br /><br />my $rs = new RiveScript();<br />$rs-&gt;loadDirectory(&quot;./cervo&quot;);<br />$rs-&gt;sortReplies();<br /><br />open (my $voice, &quot;&lt;&quot;, &quot;/root/bot/jarvis/recovocal_Liste_command&quot;);<br />while (my $line = &lt;$voice&gt;) &#123;<br /> &nbsp; chomp($line);<br /> &nbsp; print &quot;You&gt; $line\n&quot;;<br /><br /> &nbsp; my $reply = $rs-&gt;reply(&quot;user&quot;, $line);<br /> &nbsp; print &quot;Bot&gt; $reply\n&quot;;<br /> &nbsp; chop($reply);<br /> &nbsp; system(&quot;/usr/local/bin/sayit&quot;, $reply);<br />&#125; &nbsp;<br />[/code]<br /><br /><br />How I can add your code : &nbsp;<br />[code]#!/usr/bin/perl<br /><br />use strict;<br />use RiveScript;<br />use CGI;<br /><br />my $co = new CGI;<br />print $co-&gt;header;<br /><br />my $message = $co-&gt;param(&quot;message&quot;); # get the user's message<br /><br />my $RS = new RiveScript;<br />$RS-&gt;loadDirectory(&quot;./replies&quot;);<br />$RS-&gt;sortReplies();<br /><br />my $reply = $RS-&gt;reply(&quot;cgi_user&quot;, $message);<br />print $reply; # send it to the browser <br />[/code]<br /><br />thanks||||
Re: rivescript with mysql|Kirsle|casey@cuvou.net|1350948118|Kirsle|xx|0|38.122.20.226|It depends on what you're trying to do.<br /><br />The first script (with vocal) would be something that runs from the command line on a local system where it can listen on a microphone and probably speak out loud in response.<br /><br />The second script is for a CGI script that would go up on a web server somewhere, and then accessed by like, http://hostname/bot.cgi or something.<br /><br />These are two vastly different environments. If your intention is to create a bot on a web page (CGI based), and have that bot be able to listen and speak out loud, this will be a tricky thing to accomplish. You'd have to find a Flash solution or use some experimental HTML 5 features to handle the vocal parts, but the rest would probably be the same. The voice recognition would happen on the client side (the end user's web browser), and the text of what they said would be sent to your CGI script. The script would return a reply (in text), which would then be read out loud on the end user's browser. I'm not familiar with any of that tech, though.<br /><br />If you're trying to write a CGI bot to run on a &quot;local&quot; web server, i.e., if you are running a web server from your main PC that's sitting right in front of you, then you may be surprised with the results if you attempt to combine those two scripts together. You'd at least need some sort of web browser based voice recognition system, but besides that, if the CGI script opens a text-to-speech program to speak out loud, it would still talk from your speakers since the web server is running on the same computer. This won't work for another user over the Internet, though - if they chatted with your bot over CGI to your computer, your computer would talk out loud to answer them, but they won't hear it because they're not physically in front of your computer. :)||||
Re: rivescript with mysql|angelz1702|fabrice@telecom4all.be|1350972014|angelz1702|xx|0|91.178.160.87|hello,<br /><br /><br />I want to create a bot command line with vocal fonction <br />but I want to store some information in a mysql database and link rivescript to mysql but in command line<br /><br />for the mment I have a cron every 30 sec run this script<br /><br />[code]#!/usr/bin/perl -w<br />use RiveScript;<br /><br />my $rs = new RiveScript();<br />$rs-&gt;loadDirectory(&quot;./cervo&quot;);<br />$rs-&gt;sortReplies();<br /><br />open (my $voice, &quot;&lt;&quot;, &quot;/root/bot/jarvis/recovocal_Liste_command&quot;);<br />while (my $line = &lt;$voice&gt;) &#123;<br /> &nbsp; chomp($line);<br /> &nbsp; print &quot;You&gt; $line\n&quot;;<br /><br /> &nbsp; my $reply = $rs-&gt;reply(&quot;user&quot;, $line);<br /> &nbsp; print &quot;Bot&gt; $reply\n&quot;;<br /> &nbsp; chop($reply);<br /> &nbsp; system(&quot;/usr/local/bin/sayit&quot;, $reply);<br />&#125; &nbsp;<br />[/code]<br /><br />but I need add mysql function but for bot command line<br />I hope you have understand my very bad english :)<br /><br />thanks for support||||
Re: rivescript with mysql|Kirsle|casey@cuvou.net|1350972664|Kirsle|xx|0|76.170.44.159|How exactly do you want to use the MySQL? Is it to keep a conversation log with the bot, or is it to store user variables for the person/people that chat with the bot, or is it to store the bot's brain (its triggers/replies/etc)?||||
Re: rivescript with mysql|angelz1702|fabrice@telecom4all.be|1350974728|angelz1702|xx|0|91.178.160.87|I want to store information <br /><br />example :<br /><br />tab 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --- &nbsp; &nbsp; tab2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ---- &nbsp; &nbsp; &nbsp;tab 3 &nbsp; &nbsp; &nbsp; <br />NameOfDevice &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fonction device &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;model device<br />disjoncteur 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Light Kitchen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Hager<br /><br />and on bot<br /><br />+ [*] &nbsp;disjonteur 1 [*]<br />- disjoncteur &lt;star1&gt;&lt;call&gt;documentation &lt;star1&gt; &nbsp;&lt;/call&gt;<br /><br />&gt; object documentation perl<br /><br /># and here connect to mysql to find infrmation about disjoncteur 1<br />and sayit :<br />disjonteur 1 model hagr is use to Kitchen <br />&lt; object<br /><br />I want to do a littl wiki for my home automation with vocal :)<br /><br />I am a little crazy :)<br /><br />thanks for support<br />||||
