<?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: Full-stack Software Engineer</title>
    <description>The latest articles on DEV Community by Full-stack Software Engineer (@high5dev).</description>
    <link>https://dev.to/high5dev</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%2F1545785%2Fff191b33-0365-4c40-b874-0b3061787461.jpg</url>
      <title>DEV Community: Full-stack Software Engineer</title>
      <link>https://dev.to/high5dev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/high5dev"/>
    <language>en</language>
    <item>
      <title>Applying an Image on a 3D Model with React Three Drei’s Decal</title>
      <dc:creator>Full-stack Software Engineer</dc:creator>
      <pubDate>Thu, 31 Oct 2024 14:15:00 +0000</pubDate>
      <link>https://dev.to/high5dev/applying-an-image-on-a-3d-model-with-react-three-dreis-decal-2a3c</link>
      <guid>https://dev.to/high5dev/applying-an-image-on-a-3d-model-with-react-three-dreis-decal-2a3c</guid>
      <description>&lt;p&gt;Adding images or patterns to 3D models can bring your scene to life, especially if you’re building applications where customization, such as tattoo previews on mannequin models, is important. Here’s how you can achieve this using Decal from React Three Drei, a powerful set of helpers for React Three Fiber.&lt;/p&gt;

&lt;p&gt;Prerequisites&lt;br&gt;
Before we start, make sure you have a project set up with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;React Three Fiber for rendering 3D scenes with React&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;React Three Drei for additional 3D helpers like Decal&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;GLTF or OBJ model of a 3D object (e.g., mannequin or similar)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;- Install Required Packages&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you haven’t yet, install @react-three/fiber, @react-three/drei, and three:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install @react-three/fiber @react-three/drei three&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Set Up the 3D Scene and Canvas&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In your main App.js file, initialize the 3D scene. Here’s the basic setup for a Canvas component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// App.js
import React from 'react';
import { Canvas } from '@react-three/fiber';
import { Suspense } from 'react';
import { Loader } from '@react-three/drei';
import Experience from './components/Experience';

function App() {
  return (
    &amp;lt;div style={{ width: '100vw', height: '100vh' }}&amp;gt;
      &amp;lt;Canvas&amp;gt;
        &amp;lt;Suspense fallback={null}&amp;gt;
          &amp;lt;Experience /&amp;gt;
        &amp;lt;/Suspense&amp;gt;
      &amp;lt;/Canvas&amp;gt;
      &amp;lt;Loader /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;- Create the Canvas Component&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Canvas component will load the model and apply a decal to it. Let’s break it down into steps.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Load the Model&lt;br&gt;
Use the useGLTF hook to load a 3D model. Make sure your model is placed in the public/models directory and is in .glb or .gltf format.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Apply the Decal Texture&lt;br&gt;
Use the Decal component from @react-three/drei. This component will allow you to apply an image to the model.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;- Building the Canvas Component&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now let’s dive into the Canvas component code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Experience.jsx
import React, { useRef } from 'react';
import { useGLTF, Decal, useTexture } from '@react-three/drei';
import { useFrame } from '@react-three/fiber';

function Experience() {
  // Load the 3D model
  const { nodes } = useGLTF('/models/male_mannequin.glb');

  // Load the texture to be applied as a decal
  const decalTexture = useTexture('/textures/tattoo.png');

  // A ref for rotating the model (optional)
  const modelRef = useRef();

  // Rotate the model for some interaction
  useFrame(() =&amp;gt; {
    modelRef.current.rotation.y += 0.01;
  });

  return (
    &amp;lt;group ref={modelRef} position={[0, -1.5, 0]}&amp;gt;
      {/* Mannequin model */}
      &amp;lt;mesh geometry={nodes.mannequin.geometry} castShadow receiveShadow&amp;gt;
        &amp;lt;meshStandardMaterial color="lightgrey" /&amp;gt;

        {/* Decal component to apply the image */}
        &amp;lt;Decal 
          position={[0, 0.5, 0.6]}     // Adjust position based on your model's needs
          rotation={[Math.PI, 0, 0]}    // Adjust rotation for orientation
          scale={0.3}                   // Adjust size of the decal
          map={decalTexture}            // Pass the loaded texture here
        /&amp;gt;
      &amp;lt;/mesh&amp;gt;
    &amp;lt;/group&amp;gt;
  );
}

export default Experience;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;- Adjusting the Decal Properties&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To make sure the decal appears exactly where you want it, experiment with these properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;position: [x, y, z] coordinates to place the decal on the model. Adjust these based on the model’s geometry.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;rotation: [x, y, z] values to orient the decal. Use radians, e.g., Math.PI for 180 degrees.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;scale: Controls the size of the decal. Start small (e.g., 0.1 or 0.3) and increase as needed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;- Adding a Fallback or Error Boundary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If the model or texture is having trouble loading, wrap the Experience component in a fallback or error boundary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Suspense fallback={&amp;lt;LoadingScreen /&amp;gt;}&amp;gt;
  &amp;lt;Experience /&amp;gt;
&amp;lt;/Suspense&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;- Testing and Fine-Tuning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Run the app, and you should see the decal applied to the 3D model! Adjust the position, rotation, and scale to fit the decal exactly where you want it.&lt;/p&gt;

&lt;p&gt;All set!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>blender</category>
    </item>
    <item>
      <title>Configuring Vite for Development Over VPN 🚀</title>
      <dc:creator>Full-stack Software Engineer</dc:creator>
      <pubDate>Mon, 07 Oct 2024 18:53:32 +0000</pubDate>
      <link>https://dev.to/high5dev/configuring-vite-for-development-over-vpn-50e0</link>
      <guid>https://dev.to/high5dev/configuring-vite-for-development-over-vpn-50e0</guid>
      <description>&lt;p&gt;Vite is an amazing development tool with lightning-fast build times, hot-module reloading, and an intuitive configuration setup. However, working behind a VPN can sometimes cause issues when developing locally. Let’s walk through how to configure Vite to work seamlessly over a VPN.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the Issue with VPNs?
&lt;/h2&gt;

&lt;p&gt;When you’re using a VPN, network requests and traffic are often tunneled through different gateways. This can affect how local development servers (like Vite) interact with your machine’s network interfaces. The most common issues are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Host Binding: Vite defaults to localhost (127.0.0.1), which might not be accessible over the VPN.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Port Conflicts: Certain VPNs block or reserve specific ports.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Fixing Vite Configuration for VPNs
&lt;/h2&gt;

&lt;p&gt;To solve these issues, you need to tweak the Vite configuration slightly. Luckily, Vite offers an easy way to modify how the dev server behaves.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Bind Vite to Your Local Network Interface
&lt;/h3&gt;

&lt;p&gt;By default, Vite binds to localhost. You can configure Vite to bind to all network interfaces using the server.host option. This will allow devices connected to your local network (even over a VPN) to access your development server.&lt;/p&gt;

&lt;p&gt;Edit your &lt;code&gt;vite.config.js&lt;/code&gt; (or vite.config.ts if you're using TypeScript):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// vite.config.js
export default {
  server: {
    host: '0.0.0.0', // Bind to all available network interfaces
    port: 3000, // Default port, change if necessary
  },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Consider Changing the Port (if needed)
&lt;/h3&gt;

&lt;p&gt;Some VPNs block certain ports or cause conflicts with ports you’re trying to use. If you notice connection issues, try using a different port. You can easily change the port in your &lt;code&gt;vite.config.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// vite.config.js
export default {
  server: {
    host: '0.0.0.0',
    port: 8080, // Change to a different port, like 8080 or 5000
  },
};

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Use HTTPS if Required
&lt;/h3&gt;

&lt;p&gt;Some VPNs require secure communication over HTTPS. If that’s the case, you can enable HTTPS in Vite by generating SSL certificates or using self-signed ones.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// vite.config.js
import fs from 'fs';
import path from 'path';

export default {
  server: {
    host: '0.0.0.0',
    https: {
      key: fs.readFileSync(path.resolve(__dirname, 'path/to/your/ssl-key.pem')),
      cert: fs.readFileSync(path.resolve(__dirname, 'path/to/your/ssl-cert.pem')),
    },
  },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Tweak Your Firewall or VPN Configuration
&lt;/h3&gt;

&lt;p&gt;If you still face connectivity issues, ensure your VPN or firewall isn't blocking traffic on the port Vite uses. You might need to:&lt;/p&gt;

&lt;p&gt;Allow traffic to the development server port (e.g., 3000) in your VPN’s settings.&lt;br&gt;
Disable or adjust your firewall rules for local development.&lt;/p&gt;

&lt;h3&gt;
  
  
  Wrapping Up
&lt;/h3&gt;

&lt;p&gt;Working with Vite over a VPN doesn’t have to be a hassle. By binding Vite to all network interfaces, tweaking the port, and potentially adding HTTPS support, you can keep your development environment smooth—even when working remotely behind a VPN.&lt;/p&gt;

&lt;p&gt;Have any other tips or issues you encountered? Drop them in the comments below! 💬&lt;/p&gt;

&lt;p&gt;Happy coding! 🎉&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>vite</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Send Messages via Telegram in a Next.js Application</title>
      <dc:creator>Full-stack Software Engineer</dc:creator>
      <pubDate>Wed, 25 Sep 2024 20:30:43 +0000</pubDate>
      <link>https://dev.to/high5dev/how-to-send-messages-via-telegram-in-a-nextjs-application-1o93</link>
      <guid>https://dev.to/high5dev/how-to-send-messages-via-telegram-in-a-nextjs-application-1o93</guid>
      <description>&lt;p&gt;Sending notifications or form submissions directly to your Telegram can be a very useful feature in a web application. For example, you might want to receive contact form submissions or system notifications instantly in your Telegram account or group. In this tutorial, we’ll show how to send messages directly to Telegram from a Next.js app using the Telegram Bot API.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the Telegram Bot API?
&lt;/h2&gt;

&lt;p&gt;The Telegram Bot API allows developers to control bots and send messages via HTTP requests. A bot is an automated account on Telegram that can send and receive messages, and using it to notify you or your team of new submissions from your web app is a great use case.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 1: Setting Up Your Telegram Bot
&lt;/h2&gt;

&lt;p&gt;To send messages via the Telegram Bot API, you first need to create a bot and get its Bot Token.&lt;/p&gt;

&lt;h3&gt;
  
  
  1.1 Create a Bot Using BotFather
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Open Telegram and search for &lt;a class="mentioned-user" href="https://dev.to/botfather"&gt;@botfather&lt;/a&gt;. BotFather is the official bot used to create and manage Telegram bots.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Start a chat with BotFather and type /start.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To create a new bot, type /newbot and follow the instructions:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Choose a name for your bot (e.g., MyNotificationBot).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose a username for your bot (must end with bot, like MyNotifBot_bot).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Once the bot is created, BotFather will give you a Bot Token. This token looks something like this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;123456789:ABCdefGhIJKlmNOPqrsTUVwxyz123456789
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Save this token because you'll need it later.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  1.2 Get Your Chat ID
&lt;/h3&gt;

&lt;p&gt;The Chat ID is the ID of the user or group where the bot will send messages.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For a Personal Chat: Start a conversation with your bot in Telegram and send any message. Then, visit the following URL to get updates from the bot:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://api.telegram.org/bot&amp;lt;YOUR_BOT_TOKEN&amp;gt;/getUpdates
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Replace  with your actual bot token. The JSON response will include a chat object that contains the id. This is your Chat ID.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;For a Group Chat: Add your bot to a group, send a message, and use the same URL above to get the group Chat ID. Group Chat IDs typically start with a - (e.g., -987654321).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: Set Up a Next.js API Route
&lt;/h2&gt;

&lt;p&gt;Now that you have your bot's token and chat ID, you can set up a Next.js API route to send messages via Telegram.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.1 Create an API Route
&lt;/h3&gt;

&lt;p&gt;In Next.js, you can create an API route to handle the message sending logic. In this case, we’ll send a POST request to the Telegram Bot API whenever someone submits a form on the website.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// pages/api/contact.js
import axios from 'axios';

export default async function handler(req, res) {
  if (req.method === 'POST') {
    const { name, email, message } = req.body;

    // Replace with your actual bot token and chat ID
    const botToken = process.env.TELEGRAM_BOT_TOKEN;
    const chatId = process.env.TELEGRAM_CHAT_ID;

    const telegramUrl = `https://api.telegram.org/bot${botToken}/sendMessage`;

    const text = `
      New message from ${name} \n
      Email: ${email} \n
      Message: ${message}
    `;

    try {
      // Send the message via the Telegram Bot API
      const response = await axios.post(telegramUrl, {
        chat_id: chatId,
        text: text,
      });

      if (response.data.ok) {
        return res.status(200).json({ success: true, message: 'Message sent successfully!' });
      } else {
        return res.status(500).json({ success: false, message: 'Failed to send message.' });
      }
    } catch (error) {
      console.error('Error sending message to Telegram:', error);
      return res.status(500).json({ success: false, message: 'Error sending message.' });
    }
  } else {
    return res.status(405).json({ message: 'Method not allowed' });
  }
}

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Breakdown:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Telegram Bot Token and Chat ID: We use environment variables to store sensitive data like the bot token and chat ID.&lt;/li&gt;
&lt;li&gt;POST Request to Telegram API: We send the message via the Telegram Bot API using the /sendMessage endpoint.&lt;/li&gt;
&lt;li&gt;Axios: The axios library is used to make the HTTP request to Telegram's API.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  2.2 Add Environment Variables
&lt;/h3&gt;

&lt;p&gt;To avoid hardcoding sensitive data in your code, store your bot token and chat ID in environment variables. In your .env.local file, add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_chat_id
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Make sure to restart your development server after adding or updating the environment variables.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Step 3: Create a Contact Form
&lt;/h2&gt;

&lt;p&gt;Now that the API route is ready, let's create a Contact Form component to allow users to submit messages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";
import { useState } from 'react';
import axios from 'axios';
import { toast } from 'react-toastify'; // Optional for notifications

function ContactForm() {
  const [userInput, setUserInput] = useState({
    name: '',
    email: '',
    message: ''
  });

  const handleChange = (e) =&amp;gt; {
    const { name, value } = e.target;
    setUserInput({ ...userInput, [name]: value });
  };

  const handleSubmit = async (e) =&amp;gt; {
    e.preventDefault();

    try {
      const response = await axios.post('/api/contact', userInput);

      if (response.status === 200) {
        toast.success('Message sent successfully!');
        setUserInput({ name: '', email: '', message: '' });
      } else {
        toast.error('Failed to send message.');
      }
    } catch (error) {
      toast.error('Error sending message.');
    }
  };

  return (
    &amp;lt;form onSubmit={handleSubmit}&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;label&amp;gt;Your Name:&amp;lt;/label&amp;gt;
        &amp;lt;input
          type="text"
          name="name"
          value={userInput.name}
          onChange={handleChange}
          required
        /&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;label&amp;gt;Your Email:&amp;lt;/label&amp;gt;
        &amp;lt;input
          type="email"
          name="email"
          value={userInput.email}
          onChange={handleChange}
          required
        /&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;label&amp;gt;Your Message:&amp;lt;/label&amp;gt;
        &amp;lt;textarea
          name="message"
          value={userInput.message}
          onChange={handleChange}
          required
        /&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;button type="submit"&amp;gt;Send Message&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  );
}

export default ContactForm;

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Breakdown:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;useState: Handles form state for the user’s name, email, and message.&lt;/li&gt;
&lt;li&gt;handleSubmit: Sends a POST request to your /api/contact endpoint with the form data.&lt;/li&gt;
&lt;li&gt;axios: We use axios to send the form data to the server-side API route.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Step 4: Deploy Your Application
&lt;/h2&gt;

&lt;p&gt;Once your contact form and API route are set up, you can deploy your app. If you’re using Vercel or Netlify, the deployment process is seamless. Don't forget to add your environment variables in your production settings.&lt;/p&gt;

&lt;p&gt;For Vercel:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Navigate to the Project Settings.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add your environment variables (TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID) in the Environment Variables section.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Integrating the Telegram Bot API with Next.js is an excellent way to receive notifications and contact form submissions without the need for complicated backend infrastructure. By leveraging Telegram's Bot API, you can automate messages and stay updated on user interactions instantly.&lt;/p&gt;

&lt;p&gt;With this setup, you’ll have your contact form submissions sent directly to your personal or group Telegram chat. 🚀&lt;/p&gt;

&lt;p&gt;If you have any questions or feedback, feel free to drop a comment below. Happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Send Emails via EmailJS in a Next.js Application</title>
      <dc:creator>Full-stack Software Engineer</dc:creator>
      <pubDate>Wed, 25 Sep 2024 20:10:07 +0000</pubDate>
      <link>https://dev.to/high5dev/how-to-send-emails-via-emailjs-in-a-nextjs-application-44p5</link>
      <guid>https://dev.to/high5dev/how-to-send-emails-via-emailjs-in-a-nextjs-application-44p5</guid>
      <description>&lt;p&gt;When creating a web application, sending emails is often necessary for contact forms, notifications, and other purposes. Setting up your own SMTP server may seem overwhelming, but there are services like EmailJS that can handle email sending without the need for a backend. In this guide, I will demonstrate how to integrate EmailJS into your Next.js project, allowing you to easily send messages from your client-side application.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is EmailJS?
&lt;/h2&gt;

&lt;p&gt;EmailJS allows you to send emails directly from JavaScript without needing any server infrastructure. It connects to popular email services like Gmail, Outlook, and others, making it easier to send transactional emails directly from the frontend.&lt;/p&gt;

&lt;p&gt;Let’s get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Setting Up EmailJS
&lt;/h2&gt;

&lt;p&gt;First, head over to EmailJS and sign up for an account. Once signed in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Go to the Email Services section and select your email service (e.g., Gmail).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set up a new Email Template. This template defines the structure of your email, and you can customize the fields to capture name, email, and message from your contact form.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get your Service ID, Template ID, and User ID from the EmailJS dashboard, as you’ll need these in the code.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: Install EmailJS SDK
&lt;/h2&gt;

&lt;p&gt;To use EmailJS in your project, you’ll need the EmailJS SDK. You can install it via npm or yarn:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @emailjs/browser
# or
yarn add @emailjs/browser
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Create the Contact Form
&lt;/h2&gt;

&lt;p&gt;Let’s create a simple contact form that will allow users to send messages directly to your email. In Next.js, we can set up the form as a component.&lt;/p&gt;

&lt;p&gt;Here’s an example of a Contact Form component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";
import { useState } from "react";
import { toast } from "react-toastify"; // For notifications
import emailjs from '@emailjs/browser';

function ContactForm() {
  const [userInput, setUserInput] = useState({
    name: "",
    email: "",
    message: ""
  });

  const handleChange = (e) =&amp;gt; {
    const { name, value } = e.target;
    setUserInput({
      ...userInput,
      [name]: value
    });
  };

  const handleSubmit = async (e) =&amp;gt; {
    e.preventDefault();

    const serviceID = process.env.NEXT_PUBLIC_EMAILJS_SERVICE_ID;
    const templateID = process.env.NEXT_PUBLIC_EMAILJS_TEMPLATE_ID;
    const userID = process.env.NEXT_PUBLIC_EMAILJS_PUBLIC_KEY;

    try {
      const emailParams = {
        name: userInput.name,
        email: userInput.email,
        message: userInput.message
      };

      const res = await emailjs.send(serviceID, templateID, emailParams, userID);

      if (res.status === 200) {
        toast.success("Message sent successfully!");
        setUserInput({
          name: "",
          email: "",
          message: ""
        });
      }
    } catch (error) {
      toast.error("Failed to send message. Please try again later.");
    }
  };

  return (
    &amp;lt;form onSubmit={handleSubmit}&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;label&amp;gt;Your Name:&amp;lt;/label&amp;gt;
        &amp;lt;input
          type="text"
          name="name"
          value={userInput.name}
          onChange={handleChange}
          required
        /&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;label&amp;gt;Your Email:&amp;lt;/label&amp;gt;
        &amp;lt;input
          type="email"
          name="email"
          value={userInput.email}
          onChange={handleChange}
          required
        /&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;label&amp;gt;Your Message:&amp;lt;/label&amp;gt;
        &amp;lt;textarea
          name="message"
          value={userInput.message}
          onChange={handleChange}
          required
        /&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;button type="submit"&amp;gt;Send Message&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  );
}

export default ContactForm;

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

&lt;/div&gt;



&lt;p&gt;Breakdown:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;useState: Manages form state (name, email, and message).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;emailjs.send: Sends the email to your email service via EmailJS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;toast: Displays a notification on success or failure (optional, but you can install react-toastify to manage notifications).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 4: Environment Variables
&lt;/h2&gt;

&lt;p&gt;To avoid hardcoding sensitive data (like service ID, template ID, and user ID), store them in environment variables. Create a .env.local file in the root of your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NEXT_PUBLIC_EMAILJS_SERVICE_ID=your_service_id
NEXT_PUBLIC_EMAILJS_TEMPLATE_ID=your_template_id
NEXT_PUBLIC_EMAILJS_PUBLIC_KEY=your_user_id
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note: Be sure to restart your development server after adding or updating environment variables.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Step 5: Deploy Your App
&lt;/h2&gt;

&lt;p&gt;Now that your contact form is integrated with EmailJS, it’s ready to be deployed. If you’re using Vercel, deploying a Next.js app is straightforward:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Push your code to GitHub or any Git provider.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Head over to the Vercel dashboard, connect your GitHub repository, and deploy your app.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Don’t forget to add the environment variables in your Vercel settings to ensure the email functionality works in production!&lt;/p&gt;

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

&lt;p&gt;Integrating EmailJS with Next.js makes it incredibly easy to send emails directly from your frontend application without needing a backend server. It’s perfect for contact forms, feedback forms, or any other scenario where you need to send emails.&lt;/p&gt;

&lt;p&gt;If you have any questions or run into issues, feel free to drop a comment below. Happy coding! 🚀&lt;/p&gt;

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