<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Temidire Oluwasogo</title>
    <description>The latest articles on DEV Community by Temidire Oluwasogo (@temid).</description>
    <link>https://dev.to/temid</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1267620%2Fcb31cbfb-b9d7-4e9c-a824-f8c5fedece70.jpg</url>
      <title>DEV Community: Temidire Oluwasogo</title>
      <link>https://dev.to/temid</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/temid"/>
    <language>en</language>
    <item>
      <title>Building a Twilio-Powered App with Next.js and OpenAI GPT-3.</title>
      <dc:creator>Temidire Oluwasogo</dc:creator>
      <pubDate>Tue, 13 Feb 2024 11:17:11 +0000</pubDate>
      <link>https://dev.to/temid/building-a-twilio-powered-app-with-nextjs-and-openai-gpt-3-3l91</link>
      <guid>https://dev.to/temid/building-a-twilio-powered-app-with-nextjs-and-openai-gpt-3-3l91</guid>
      <description>&lt;p&gt;In this article, you will learn how to create a Twilio-powered app with OpenAI’s GPT-3 using Twilio Programmable SMS. The app will be created using Next.js. Next.js is a powerful React framework that comes with its server-side functions and also has API routes that are used to handle HTTP requests between the server and client. Next.js is fully capable of handling both front-end and back-end functionalities and communication.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Overview
&lt;/h2&gt;

&lt;p&gt;In this article, the project we will be building is a Meeting Invite app. We will use Next.js to create both the front-end and back-end due to its server-side and client-side capabilities. We will also make use of the &lt;a href="https://platform.openai.com/docs/guides/gpt" rel="noopener noreferrer"&gt;OpenAI&lt;/a&gt; GPT-3 text-Davinci-003 engine, to generate the meeting text body and finally, we will make use of the &lt;a href="https://www.twilio.com/docs/sms/api" rel="noopener noreferrer"&gt;Twilio Programmable SMS&lt;/a&gt; API to send SMS messages to the desired phone numbers. You can get the whole project from &lt;a href="https://github.com/temidd/Twilio-powered-app-using-Nextjs-OpenAI-GPT-3" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; and follow along. Though we will go through all the steps to build the project. &lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;In other to go ahead with the article you will need the following:&lt;br&gt;
Visual Studio code editor&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;a href="https://www.twilio.com/try-twilio" rel="noopener noreferrer"&gt;Twilio&lt;/a&gt; account&lt;/li&gt;
&lt;li&gt;An &lt;a href="https://openai.com/" rel="noopener noreferrer"&gt;OpenAI&lt;/a&gt; account&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/react-phone-number-input" rel="noopener noreferrer"&gt;React-phone-number-input&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;OpenAI Api key&lt;/li&gt;
&lt;li&gt;Twilio&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With all that stated let's begin creating the app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Working on the front end
&lt;/h2&gt;

&lt;p&gt;The first step is to create the front end but before that here is a snapshot of the project below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F24x8z00811b72wpz8r23.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F24x8z00811b72wpz8r23.png" alt="Frontend view"&gt;&lt;/a&gt;&lt;br&gt;
The front end is not the most beautiful but it will do for our project.&lt;br&gt;
In other to create the Next.js app, you have to use the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-next-app meeting-invite-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next, we will also install the other libraries we need.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm  install twilio openAiApi react-phone-numbers-input
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Or if you cloned from the repo you can use the command &lt;code&gt;npm install&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After installing the necessary dependencies, open the Next.js app in VS code. &lt;br&gt;
Then open the &lt;code&gt;index.js&lt;/code&gt; file located in the pages folder and write the following code:&lt;br&gt;
First, import PhoneNumber from react-phone-number-input,&lt;br&gt;
import PhoneNumber from 'react-phone-number-input'&lt;/p&gt;

&lt;p&gt;Next, input the following lines of code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div className={styles.container}&amp;gt;
  &amp;lt;Head&amp;gt;
    &amp;lt;title&amp;gt;Create Next App&amp;lt;/title&amp;gt;
    &amp;lt;meta name="description" content="Generated by create next app" /&amp;gt;
    &amp;lt;link rel="icon" href="/favicon.ico" /&amp;gt;
  &amp;lt;/Head&amp;gt;

  &amp;lt;div className={styles.formContent}&amp;gt;
    &amp;lt;div className={styles.header}&amp;gt;
      &amp;lt;h1&amp;gt;Meeting Inviter&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;div&amp;gt;
      &amp;lt;form className={styles.inputForm} onSubmit={sendData} method="POST"&amp;gt;
        &amp;lt;input
          className={styles.input}
          type="text"
          name="employeeName"
          placeholder="Name of employee"
          onChange={(e) =&amp;gt; setEmployeeName(e.target.value)}
        /&amp;gt;
        &amp;lt;PhoneInput
          className={styles.phoneNumber}
          placeholder="Enter Employee number"
          value={phoneNumber}
          onChange={setValue}
        /&amp;gt;
        &amp;lt;input
          className={styles.input}
          type="text"
          name="messageBody"
          placeholder="Enter meeting title"
          onChange={(e) =&amp;gt; setTitle(e.target.value)}
        /&amp;gt;
        &amp;lt;textarea
          className={styles.textArea}
          placeholder="Enter meeting descreiption"
          rows="20"
          cols="50"
          onChange={(e) =&amp;gt; setMessageBody(e.target.value)}
        /&amp;gt;
        &amp;lt;button className={styles.button} type="submit"&amp;gt;
          Send
        &amp;lt;/button&amp;gt;
      &amp;lt;/form&amp;gt;
      &amp;lt;div&amp;gt;{sent &amp;amp;&amp;amp; &amp;lt;div className={styles.alert}&amp;gt;Message sent&amp;lt;/div&amp;gt;}&amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The code above is used to create a simple form for our front end and in the code you will notice some functions used to get the values from our form. Those functions are the state functions and we haven’t imported our &lt;code&gt;useState&lt;/code&gt; hook to handle them. To do so we have to import the &lt;code&gt;useState&lt;/code&gt; hook and destructure it as follows:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from "react";

const [employeeName, setEmployeeName] = useState("");
const [phoneNumber, setValue] = useState("");
const [title, setTitle] = useState("");
const [messageBody, setMessageBody] = useState("");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now the front end is okay the only thing remaining is to add a CSS file. You can do that by importing the CSS module into the index file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import styles from '../styles/Home.module.css'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After that, you can run the file with &lt;code&gt;npm run dev&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting and sending form data
&lt;/h3&gt;

&lt;p&gt;Now that we have our front end we have to work on how to get our data from the form and send it to the Next.js backend which is the API route. In other to do that since the states have already been created, we need a function to get the values from the states and send them to the specific &lt;code&gt;API&lt;/code&gt; route which will handle the data. If you look at the code above we, inside the form element, there is an &lt;code&gt;onSubmit&lt;/code&gt; and a &lt;code&gt;method&lt;/code&gt; property that will run the &lt;code&gt;sendData&lt;/code&gt; function and set the HTTP request method to POST. &lt;br&gt;
Now you have to create the &lt;code&gt;sendData&lt;/code&gt; function by writing the following code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sendData = async (event) =&amp;gt; {
  event.preventDefault();
  // get data from the react state hooks
  const data1 = {
    name: employeeName,
    messageTitle: title,
    message: messageBody,
  };
  const mainObject1 = JSON.stringify(data1);
  const endPoint1 = "/api/textAI";
  //Set the parameters to be sent to the textAI api route
  const params1 = {
    method: "POST",
    body: mainObject1,
  };

  //Get the response sent back from textAI API route
  const response = await fetch(endPoint1, params1);

  const myData = await response.json();
  const { textData } = myData;

  console.log(`This data is from openAIApi: ${textData} `);
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The code above is a function that gets the name,  message title, and message from the state hooks and sends them as part of the object body to the &lt;code&gt;textAI.js&lt;/code&gt; API route. The function also handles the response which is from the API route.&lt;/p&gt;

&lt;p&gt;We still have another API routes to handle in the code,  which is the data.js API route. In other to handle the request and response write the following code in the same function below the last line of code above:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Get the data to be sent to the data.js api route
const data2 = {
  number: phoneNumber,
  text: textData,
};

const mainObject2 = JSON.stringify(data2);
const endPoint2 = "api/data";

//Set the parameters to be sent to the data api route
const params2 = {
  method: "POST",
  body: mainObject2,
};
//Get the response from the data api route
const response2 = await fetch(endPoint2, params2);
const myData2 = await response2.json();
console.log(
  `This is the Twilio response to the frontend: ${JSON.stringify(myData2)} `,
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The code above gets the number and the generated output text gotten from the &lt;code&gt;textAI.js&lt;/code&gt; API route and sends it to the &lt;code&gt;data.js&lt;/code&gt; API route which also sends back a response to the front end.&lt;/p&gt;

&lt;p&gt;The function &lt;code&gt;sendData&lt;/code&gt; is called when the send button is clicked. &lt;/p&gt;

&lt;h2&gt;
  
  
  Working on the API routes
&lt;/h2&gt;

&lt;p&gt;Now that the function &lt;code&gt;sendData&lt;/code&gt; is created on the front end, let us set work on the API routes that will handle the data gotten from the front end and send back a response to the back end. This is where the main app functionality will occur.&lt;br&gt;
We will create two API routes named:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;textAI.js&lt;/li&gt;
&lt;li&gt;data.js
You can name your API any name you like. But for this article let us stick to the names above.
You might wonder, what do &lt;code&gt;textAI.js&lt;/code&gt; and &lt;code&gt;data.js&lt;/code&gt; do? 
Well, &lt;code&gt;textAI.js&lt;/code&gt; is the API route that handles the data gotten from the front end and sends it to the OpenAI to generate text and then send it back to the front end as a response.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While &lt;code&gt;data.js&lt;/code&gt; gets the generated text and the phone number from the front end and makes an API call to Twilio and Twilio then sends the generated text to the phone number.&lt;br&gt;
Now let us work on our api route. To do so, enter into the pages folder, inside the folder enter into the &lt;code&gt;api&lt;/code&gt; folder then create two files named &lt;code&gt;text.js&lt;/code&gt; and &lt;code&gt;data.js&lt;/code&gt;.&lt;br&gt;
After creating the files, go to your terminal or shell and install the Twilio and OpenAI library using the command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install twilio openai
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Also, you need an environment variable to store your API keys. To create it, in the root directory of your next js app create a file named &lt;code&gt;.env.local&lt;/code&gt; this file will hold all your API keys.&lt;/p&gt;

&lt;h3&gt;
  
  
  Making an API call to OPenAI
&lt;/h3&gt;

&lt;p&gt;Now, let us make an API call to OpenAI. To do so you have to import the OpenaiAPI from the &lt;code&gt;openai&lt;/code&gt; library and also configure it to initialize your API key. Inside the &lt;code&gt;textAI.js&lt;/code&gt; file write the following code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Configuration, OpenAIApi } from "openai";
export default async function postMethod(req, res) {
  const { name, message, messageTitle } = JSON.parse(req.body);
  const configuration = new Configuration({
    apiKey: process.env.openAiKey,
  });
  const openai = new OpenAIApi(configuration);
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The code above enables you to make use of the OpenAI library. You will need to import &lt;code&gt;OpenAIApi&lt;/code&gt; and Configuration functions from the &lt;code&gt;openai&lt;/code&gt; library. The configuration method enables you to configure the &lt;code&gt;openai&lt;/code&gt; library to use your API key.&lt;br&gt;
While the &lt;code&gt;OpenAIApi&lt;/code&gt; function enables you to initialize the configuration which holds the API key. &lt;/p&gt;

&lt;p&gt;Next, you need to get the data coming from the request body of the front end and send it for text generation and also send back a response by writing the following code inside the &lt;code&gt;postMethod&lt;/code&gt; function:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Edit the message to send to OpenAI
const prompt = `${message} to ${name} with title ${messageTitle}`;
try {
  //Send the prompt with the necessary parameters
  const response = await openai.createCompletion({
    model: "text-davinci-003",
    prompt,
    temperature: 0,
    max_tokens: 100,
    n: 1,
  });
  //Get the response from OpenAI GPT-3
  const textOutput = response.data.choices;
  const textData = textOutput[0].text;
  console.log(textOutput);
  console.log("main data: ", textData);
  //Send a response back to the front end
  res.status(200).json({ textData });
} catch (error) {
  console.error(error);
  res.status(500).json({ error: "An error occured while fetcing from openAI" });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the code above the function &lt;code&gt;openai.createCompletion&lt;/code&gt; was used to add the parameters and make a call to GPT-3 &lt;code&gt;text-DaVinci-003&lt;/code&gt; engine. This engine or model is used to generate text based on input. The input is structured as in a string literal and assigned to the variable prompt.&lt;br&gt;
&lt;code&gt;Prompt&lt;/code&gt; is the input that is sent to GPT-3 for text generation.&lt;br&gt;
Temperature is the amount of randomness set. &lt;br&gt;
&lt;code&gt;Max_tokens&lt;/code&gt; represents the number of units of inputs or outputs that can be generated. &lt;code&gt;n&lt;/code&gt; refers to the number of tokens.&lt;/p&gt;

&lt;p&gt;If you run the app you will get the generated text from OpenAI GPT-3. It was destructured in the sendData function in index.js and set to the generatedText state.&lt;/p&gt;

&lt;p&gt;Sending the message using Twilio API&lt;br&gt;
This is another main part of the application. Here you have to request the Twilio API to send the generated text to the recipient's phone number. &lt;br&gt;
In other to do this, open the &lt;code&gt;data.js&lt;/code&gt; file and import the Twilio library using the code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import twilio from "twilio";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After that, you need to get your &lt;code&gt;Twilio API key&lt;/code&gt; and &lt;code&gt;accountSID&lt;/code&gt;. Also, make sure you put them in the &lt;code&gt;.env.local&lt;/code&gt; file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const authToken = process.env.AuthToken;
const accountSID = process.env.AccountSID;
const client = twilio(accountSID, authToken);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next, you need to write the code to make the call to Twilio.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Get the data from the front-end request body
const { number, text } = JSON.parse(req.body);
//Send the text
client.messages
  .create({
    from: "+13157125351",
    to: number,
    body: text,
  })
  //Send back a response
  .then((message) =&amp;gt; {
    res.status(200).json({ messageSId: message.sid });
  })
  .catch((err) =&amp;gt; {
    res.status(500).json({ err: err.message });
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You use the function &lt;code&gt;client.messages.create()&lt;/code&gt; to tell the Twilio API to send a message to the recipient. Inside the function there is an object parameter as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;From&lt;/li&gt;
&lt;li&gt;To&lt;/li&gt;
&lt;li&gt;Body
The &lt;code&gt;from&lt;/code&gt; object property is used to set your Twilio number. You get a Twilio number once you sign up for Twilio. The number will be able to send SMS messages and also place calls.
The &lt;code&gt;to&lt;/code&gt; object property is used to set the destination number to receive the message. It should contain the recipient's number.
And the &lt;code&gt;body&lt;/code&gt; object is used to set the message to be sent to the recipient. &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Do not omit any of the parameters else it won’t send.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The above code will look like the one below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import twilio from "twilio";
export default async function postMethod(req, res) {
  const authToken = process.env.AuthToken;
  const accountSID = process.env.AccountSID;
  const client = twilio(accountSID, authToken);
  //Get the data from the front-end request body
  const { number, text } = JSON.parse(req.body);
  //Send the text
  client.messages
    .create({
      from: "+13157125351",
      to: number,
      body: text,
    })
    //Send back a response
    .then((message) =&amp;gt; {
      res.status(200).json({ messageSId: message.sid });
    })
    .catch((err) =&amp;gt; {
      res.status(500).json({ err: err.message });
    });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After writing the code above, we just have to add one thing to our front end which is to show a text when the message is successfully sent. &lt;br&gt;
To do that,  we have to create a div that will show the text &lt;code&gt;message sent&lt;/code&gt; You can add styles to it though, but you don't need to worry the GitHub repository with the complete styles used for this project will be added. &lt;br&gt;
To make the message pop up we need to do what is called conditional rendering. To do so, open the &lt;code&gt;index.js&lt;/code&gt; file, create a state to handle the rendering;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [sent, setSent] = useState(false);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Inside the sendData function at the bottom, add the following code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { err } = myData2;
if (!err) {
  setSent(true);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then below the form element add the following code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div&amp;gt;{sent &amp;amp;&amp;amp; &amp;lt;div className={styles.alert}&amp;gt;Message sent&amp;lt;/div&amp;gt;}&amp;lt;/div&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After that, you can run the entire app using the command &lt;code&gt;npm run dev&lt;/code&gt;. You will get a similar one to the one below;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvqfatxzwpxg9q9q26fdq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvqfatxzwpxg9q9q26fdq.png" alt="Initial view"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftknkt6nxpbrb4xd2ye3s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftknkt6nxpbrb4xd2ye3s.png" alt="Form input"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feu76nep1fti7kxylygc5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feu76nep1fti7kxylygc5.png" alt="console message"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Conclusion&lt;br&gt;
In this article, you learned to build a Twilio-powered app using Next.js and OpenAI GPT-3. The app can send text generated from GPT-3 and send it to the recipient’s phone number by using Twilio Programmable SMS. &lt;br&gt;
Remember in other to use the Twilio programmable SMS you have to create an account on &lt;a href="https://www.twilio.com/try-twilio" rel="noopener noreferrer"&gt;Twilio&lt;/a&gt;. When you create an account you get a phone number and free credits. In case the free credits are exhausted or maybe your free trial expires you have to then upgrade to a paid plan. With the paid plan you get even more capabilities. &lt;br&gt;
You can also check the &lt;a href="https://www.twilio.com/docs/sms/api" rel="noopener noreferrer"&gt;Twilio programmable SMS API&lt;/a&gt; for more information and also check out OpenAI API documentation for more information on how to use their API.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Webpack Vs Parcel: A quick Look for Developers</title>
      <dc:creator>Temidire Oluwasogo</dc:creator>
      <pubDate>Sun, 28 Jan 2024 07:37:12 +0000</pubDate>
      <link>https://dev.to/temid/webpack-vs-parcel-a-quick-look-for-developers-1n30</link>
      <guid>https://dev.to/temid/webpack-vs-parcel-a-quick-look-for-developers-1n30</guid>
      <description>&lt;p&gt;As developers, we constantly strive to improve our workflows and build efficient, performant applications. One critical aspect of web development is bundling and optimizing our code for production. Two popular tools that help us achieve this are Webpack and Parcel. In this article, we’ll take a closer look at these bundlers, exploring their key differences and helping you make an informed choice for your projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction to Webpack and Parcel
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Webpack: The Battle-Tested Bundler
&lt;/h3&gt;

&lt;p&gt;Webpack has long been a staple in the JavaScript ecosystem, gaining popularity for its powerful features and extensive configuration options. It acts as a module bundler, combining various assets such as JavaScript, CSS, and images into a single, optimized bundle. Webpack’s ability to handle complex dependencies and support for hot module replacement (HMR) makes it a go-to choice for many developers.&lt;/p&gt;

&lt;p&gt;Webpack relies on a configuration file (often named webpack.config.js) to define how the bundling process should be executed. While this configuration might seem daunting at first, it grants developers fine-grained control over the bundling process. However, the learning curve associated with Webpack configuration can be steep, especially for newcomers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Parcel: The Zero-Configuration Bundler
&lt;/h3&gt;

&lt;p&gt;In contrast, Parcel positions itself as a zero-configuration alternative to Webpack. It aims to simplify the bundling process by requiring minimal setup from developers. With Parcel, you can get started quickly without the need for an extensive configuration file. This makes it an attractive choice for small to medium-sized projects, where simplicity and rapid development are paramount.&lt;/p&gt;

&lt;p&gt;Parcel’s ability to automatically handle various file types, including HTML, CSS, and JavaScript, makes it a compelling option for developers who prefer a more straightforward setup. The absence of a complex configuration file reduces the barrier to entry, allowing developers to focus on writing code rather than spending time tweaking bundler settings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Differences Between Webpack and Parcel
&lt;/h2&gt;

&lt;p&gt;Now that we’ve introduced Webpack and Parcel, let’s delve into the key differences that set them apart.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configuration Overhead
&lt;/h3&gt;

&lt;p&gt;One of the most noticeable distinctions between Webpack and Parcel is the configuration overhead. Webpack requires developers to create and maintain a configuration file, specifying how the bundling process should be executed. This file can become intricate as projects grow in complexity, demanding a good understanding of Webpack’s configuration options.&lt;/p&gt;

&lt;p&gt;On the other hand, Parcel follows a zero-configuration philosophy. Developers can start using Parcel with minimal setup, as it automatically detects and bundles supported file types. This simplicity makes Parcel an attractive choice for beginners and those who prioritize quick development cycles.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ecosystem and Community Support
&lt;/h3&gt;

&lt;p&gt;Webpack boasts a mature and extensive ecosystem with a vast community of users. This means there are plenty of plugins and loaders available to extend Webpack’s functionality. The wealth of resources and community support makes it easier to find solutions to common issues and leverage best practices.&lt;/p&gt;

&lt;p&gt;Parcel, being a relatively newer player in the bundler scene, has a growing ecosystem. While it may not match Webpack’s breadth of plugins and loaders, Parcel’s simplicity and ease of use have gained it a dedicated user base. Developers who appreciate a lightweight approach to bundling may find Parcel’s ecosystem sufficient for their needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Performance
&lt;/h3&gt;

&lt;p&gt;Both Webpack and Parcel aim to optimize the performance of your web applications, but they take different approaches.&lt;/p&gt;

&lt;p&gt;Webpack offers advanced optimization options, such as tree shaking, code splitting, and caching. These features enable developers to create smaller bundles and improve loading times, especially for larger applications. However, achieving optimal performance with Webpack may require careful configuration and tuning. To get Webpack optimization options you can check this link, &lt;a href="https://webpack.js.org/configuration/optimization/"&gt;Webpack Configuration&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Parcel, with its zero-configuration approach, simplifies performance optimization. It automatically applies best practices, such as minification and scope hoisting, without requiring explicit configuration. While this makes Parcel an excellent choice for quick development, developers may have less control over fine-tuning performance optimizations compared to Webpack. To get the documentation on Parcel optimization, go to &lt;a href="https://en.parceljs.org/production.html"&gt;Parcel Production Docs&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Development Server and Hot Module Replacement
&lt;/h3&gt;

&lt;p&gt;Webpack’s development server, coupled with its Hot Module Replacement (HMR) feature, has been a significant selling point. HMR allows developers to see changes in real time without a full page reload, enhancing the development experience. Webpack’s dev server is highly configurable, allowing developers to tailor it to their specific needs. The &lt;a href="https://webpack.js.org/configuration/dev-server/"&gt;Webpack development server&lt;/a&gt; provides all the information about HMR and how to quickly develop an application.&lt;/p&gt;

&lt;p&gt;Parcel, too, comes with a built-in development server and HMR support out of the box. While it may not offer the same level of customization as Webpack, Parcel’s zero-configuration setup makes it straightforward to use HMR without additional setup. &lt;a href="https://en.parceljs.org/hmr.html"&gt;HMR documentation&lt;/a&gt; of Parcel shows how to improve development experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which One Should You Choose?
&lt;/h2&gt;

&lt;p&gt;The decision between Webpack and Parcel ultimately depends on your project requirements, personal preferences, and the development team’s expertise.&lt;/p&gt;

&lt;h3&gt;
  
  
  Choose Webpack If:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You require fine-grained control over the bundling process.&lt;/li&gt;
&lt;li&gt;Your project involves complex configurations and advanced optimizations.&lt;/li&gt;
&lt;li&gt;You value a mature ecosystem with extensive community support.&lt;/li&gt;
&lt;li&gt;Hot Module Replacement (HMR) is a crucial aspect of your development workflow.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Choose Parcel If:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You prioritize quick setup and a zero-configuration approach.&lt;/li&gt;
&lt;li&gt;Your project is small to medium-sized, and simplicity is essential.&lt;/li&gt;
&lt;li&gt;You are a beginner or prefer a more straightforward development process.&lt;/li&gt;
&lt;li&gt;Fine-tuning performance optimizations is less critical for your use case.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In the Webpack vs Parcel debate, there is no one-size-fits-all answer. Both bundlers have their strengths and cater to different developer preferences and project requirements. Webpack, with its extensive configurability and mature ecosystem, remains a robust choice for large, complex projects. On the other hand, Parcel’s zero-configuration approach makes it an appealing option for developers who prioritize simplicity and speed of development.&lt;/p&gt;

&lt;p&gt;Before making a decision, consider the specific needs of your project, your team’s familiarity with each tool, and the level of control and customization you require. Regardless of your choice, both Webpack and Parcel contribute to an ever-evolving landscape of tools that empower developers to build performant, scalable web applications.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
