![]() ![]() env file are retrieved before proceeding to create a new instance of the Twilio Client using your account sid and auth token. Return $client->messages->create($recipient, array('from' => "whatsapp:$twilio_whatsapp_number", 'body' => $message)) įirst, your Twilio credentials stored in your. $client = new Client($account_sid, $auth_token) $auth_token = getenv("TWILIO_AUTH_TOKEN") $twilio_whatsapp_number = getenv('TWILIO_WHATSAPP_NUMBER') Public function sendWhatsAppMessage(string $message, string $recipient) $this->sendWhatsAppMessage($response->message, $from) $response = json_decode($th->getResponse()->getBody()) $this->sendWhatsAppMessage($githubResponse->message, $from) $this->sendWhatsAppMessage($message, $from) = "*Following:* $githubResponse->following devs\n" = "*Followers:* $githubResponse->followers devs\n" = "*Number of Repos:* $githubResponse->public_repos\n" = "*Lives in:* $githubResponse->location\n" $message = "*Name:* $githubResponse->name\n" $githubResponse = json_decode($response->getBody()) $response = $client->request('GET', "$body") env file to include your WhatsApp number in this case, the sandbox number: To get started using the Twilio WhatsApp Sandbox, head over to the WhatsApp section on your Twilio dashboard and send a message to the sandbox number provided usually, +14155238886 with the provided code, which is in the format join-:Īfter successfully sending your code to the sandbox number you should receive a response like this: Since getting a Twilio number approved can take days, Twilio also provides a safe sandbox which can be used for development and testing purposes. Fortunately, Twilio provides a very robust WhatsApp API that allows you to send and receive WhatsApp messages right from your application.īefore you can start sending and receiving messages using the Twilio WhatsApp API in production, you must first get a WhatsApp Approved Twilio Number which will act as your WhatsApp number for sending and receiving messages. Open up a terminal and run the following command to generate a new Laravel application:Īs you might have already figured, to allow your chatbot to respond to messages it receives, you must have a way of sending messages via WhatsApp. Start off by first creating a new Laravel project using the Laravel installer. Laravel Installed on your local machine.To complete this tutorial, you will need the following: In this tutorial, we will build a simple WhatsApp Chatbot that allows you to get information about a developer's GitHub profile using just their username.Īfter successfully following this tutorial, you will have learned how to respond to WhatsApp messages sent to your Twilio WhatsApp number and also how to send free-form messages using the Twilio WhatsApp API. With services like the Twilio WhatsApp API, you can build custom solutions like these to power-up your chatting experience. In a perfect life, it would be better to use a chatbot to seamlessly connect with for information. Usually, this would require you to fire up your web browser which could be quite inconveniencing when time is of the essence. When these awkward situations occur, you might find yourself needing to fact check a statement or quickly look up some information. Ironically, many of these conversations don’t take place in person anymore, they happen in real-time via chat apps like WhatsApp. Conversations with family and friends about sensitive topics can often lead to arguments. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |