// Define a function to send OTP and notification function sendOtpAndNotification() { var phoneNumber = "{{ customer.phone }}"; // Get the customer's phone number var otp = generateOTP(); // Generate an OTP var message = "Your OTP is: " + otp; // Compose the message // Define the API request data var requestData = { number: phoneNumber, type: "text", message: message, instance_id: "{{ your_instance_id }}", access_token: "{{ your_access_token }}" }; // Send the API request fetch("https://wosocial.com/api/send", { method: "POST", body: JSON.stringify(requestData), headers: { "Content-Type": "application/json" } }) .then(response => response.json()) .then(data => { // Handle the API response as needed console.log("API Response:", data); // You can display a success message or handle errors here }) .catch(error => { console.error("API Error:", error); // Handle API errors here }); } // Function to generate a random 6-digit OTP function generateOTP() { return Math.floor(100000 + Math.random() * 900000); }
You can include the send_otp_notification snippet in your Shopify template where you want to trigger the OTP and notification message. For example, you might include it in the customer account page or during the checkout process.
// Include the snippet in your Shopify template {% include 'send_otp_notification' %}
You can trigger the sendOtpAndNotification function when a specific event occurs, such as when a customer clicks a button or submits a form. For example, you can add an "Send OTP" button in your template and attach an event handler to it.
// Add a button to trigger OTP and notification onclick="sendOtpAndNotification()">Send OTP
Make sure to replace {{ your_instance_id }} and {{ your_access_token }} with your actual instance ID and access token from the provided API. Additionally, customize the implementation according to your Shopify theme's structure and requirements. This example provides a basic framework for sending OTP and notification messages using the API in a dynamic Shopify environment.