![]() ![]() $requestJson = json_decode($request, true) $request = file_get_contents("php://input") listen to the POST request from Dialogflow $response = "It is $temperature degrees with $weatherDescription" * Send weather data response to Dialogflowįunction sendFulfillmentResponse($temperature, $weatherDescription) SendFulfillmentResponse($temperature, $weatherDescription) $weatherDetails =json_decode($weather, true) $weather = file_get_contents($weatherUrl) $weatherUrl = "$city&units=metric&appid=$apiKey" $apiKey = env("OPEN_WEATHER_MAP_API_KEY") ![]() * retrieves the weather data of a given city. * Makes an API call to OpenWeatherMap and In order to create a webhook, we first need to understand what a request object from Dialogflow looks like. Our next step is to make a PHP fulfillment webhook that receives a user’s input, processes it and provides an appropriate response.Įarlier we created a file called webhook.php. The response we are currently getting is from a set of responses set on the Dialogflow console. You should get a response from Dialogflow’s default welcome intent: To test our integration, let’s type “Hi” on WhatsApp. Great! We are done setting up Dialogflow and integrating it with WhatsApp. We need to copy the credentials and enter them in the Dialogflow modal along with the WhatsApp number for our sandbox. Here we will get the ACCOUNT SID and AUTH TOKEN. Lastly, let’s navigate to the console dashboard. This allows Dialogflow to handle all incoming messages from our WhatsApp sandbox. In the sandbox configuration, paste the URL we copied into the WHEN A MESSAGE COMES IN input box: Copy that URL and let’s go back to the Twilio tab we left open previously. At the bottom of that modal, we have a Request URL. Under Integrations, enable Twilio (Text Messaging) input the required credentials from Twilio. Dialogflow provides a Default Welcome Intent so that is what we will use for this part of the tutorial.įrom the menu on the left, click on “Integrations”. If you don’t have a Google account, you will need to create one.Īfter signing in, create a new agent and name it. From the landing page, click sign up for free and sign in with your Google account. Our next step is to log in to Dialogflow. That’s all we need to do for now but I suggest you leave that tab open and switch to a new tab. You will be prompted to activate your sandbox.Īfter following the instructions, you should get a message similar to this one on WhatsApp: Once you have created a new Programmable SMS project, from the dashboard, select Programmable SMS then select WhatsApp. To get started with WhatsApp, we need to first activate our Twilio Sandbox for WhatsApp. Our project directory should now look like this: From your OpenWeatherMap account, navigate to the API keys page and copy the API key to your. We will leave the webhook.php file empty for now and store our sensitive credentials in the. Inside our directory, let’s create two files: ![]() I have named mine Dialogflow-PHP-Webhook. To start off, let’s create a new directory to host our code. If you need to read up, please do so from the documentation. This tutorial requires a basic knowledge of Dialogflow. In this tutorial, we’re going to use Dialogflow with a PHP fulfillment webhook to build a conversational experience for a WhatsApp weather chatbot. It is very hard to anticipate all user inputs in our code but thanks to NLU, we’re able to handle different inputs.ĭialogFlow, powered by Google, provides a Natural Language Understanding engine that allows us to build conversational interfaces. For example, there are different ways of asking about the color of a shirt: With the help of Natural Language Understanding (NLU), which is a branch of NLP, computers are able to handle the nuances of language. Natural Language Processing (NLP), is a branch of Artificial Intelligence (AI) that helps computers understand, interpret and manipulate human language. Introduction to Natural Language Processing ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |