Haz tu Boot en 3,2,1
Nucleo GNU LINUX
Samuel Loza Ramirez
Cuando pensamos en un Boot
No es lo que te imaginas
Quienes lo usan ?
Es una tendencia
Un ChatBot es un software que se integra en un determinado sistema de mensajería
ChatBot
Nos tomara mucho tiempo hacer nuestro primer ChatBoot ?
Con la ayuda de Google es super facil
Una ves en un Hackaday
Cuando tu BOOT te dice inutil |
Taran Taran
<?php
$access_token = "EAAYi4yU312wBAHJXjWXHqY8i5vSVsNoiZCPiay5HPdYjnMcj8QT0YjA9nnndwWTmwtHJduhaqBw67bg230xYv5DcK82aLDXoX5aoGIME3vK5kQU6HhiRWEbh2fVVVw2erJZCOfptezhHZAXmq2jX9b94wxxRA4PuTyVtTMBqAZDZD";
$verify_token = "fb_time_bot";
$hub_verify_token = null;
if(isset($_REQUEST['hub_challenge'])) {
$challenge = $_REQUEST['hub_challenge'];
$hub_verify_token = $_REQUEST['hub_verify_token'];
}
if ($hub_verify_token === $verify_token) {
echo $challenge;
}
$input = json_decode(file_get_contents('php://input'), true);
$sender = $input['entry'][0]['messaging'][0]['sender']['id'];
$message = $input['entry'][0]['messaging'][0]['message']['text'];
$message_to_reply = 'KUPI';
$ddddd = busca($message_to_reply);
if(busca($message_to_reply)){
$sw = 1;
}else{
$sw = 0 ;
}
//API Url
$url = 'https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token;
//Initiate cURL.
$ch = curl_init($url);
if($sw){
//respuesta
$jsonData = '{
"recipient":{
"id":"'.$sender.'"
},
"message":{
"text":"'.$ddddd.'"
}
}';
}else{
$jsonData = '{
"recipient":{
"id":"'.$sender.'"
},
"message":{
"text":"No tenemos podemos localizar la palabra<br> intente de nuevo"
}
}';
}
//Encode the array into JSON.
$jsonDataEncoded = $jsonData;
//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
//Execute the request
if(!empty($input['entry'][0]['messaging'][0]['message'])){
$result = curl_exec($ch);
}
if($sw){
//API Url
$url = 'https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token;
//Initiate cURL.
$ch1 = curl_init($url);
$jsonData = '{
"recipient":{
"id":"'.$sender.'"
},
"message":{
"attachment":{
"type":"audio",
"payload":{
"url":"https://ia902508.us.archive.org/5/items/testmp3testfile/mpthreetest.mp3"
}
}
}
}';
//Encode the array into JSON.
$jsonDataEncoded = $jsonData;
//Tell cURL that we want to send a POST request.
curl_setopt($ch1, CURLOPT_POST, 1);
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch1, CURLOPT_POSTFIELDS, $jsonDataEncoded);
//Set the content type to application/json
curl_setopt($ch1, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
//Execute the request
if(!empty($input['entry'][0]['messaging'][0]['message'])){
$result = curl_exec($ch1);
}
}
function busca($text){
$servername = "localhost";
$username = "ayitt";
$password = "1231";
$dbname = "321";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
return "Connection failed: ";
die("Connection failed: " . $conn->connect_error);
}
else
{
$sql = "select * from aymara where palabra like '%".$text."%'";
$result = $conn->query($sql);
$cade="saasasa";
if ($result->num_rows > 0) {
// output data of each row
return "hay mas de 1";
while($row = $result->fetch_assoc()) {
return "hay mas de ___";
$cade =$cade."la palabra es : " . $row["palabra"]. " \n Pronunciacion : " . $row["pronunciacion"]. "\n";
}
} else {
$cade = 0;
}
$conn->close();
return $cade;
}
Es facil :D
Que esperas para hacer tu propio Bot
Gracias
Que esperas para hacer tu propio ChatBot
ChatBoot321
By Samuel LR
ChatBoot321
- 302