Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sarthak VarshneyRank #46 · 32K reputationPosted Mar 19, 2024, 2:46 PM EDT
WhatsApp's OTP verification in a .NET Core API, you'll need to use the Twilio API for WhatsApp, as WhatsApp does not provide a direct API for OTP verification. Twilio provides a way to send messages to WhatsApp numbers, which can be used for OTP verification.
using System; using Twilio; using Twilio.Rest.Api.V2010.Account; using Twilio.Types; public class OtpService { public void SendOtpViaWhatsApp(string toPhoneNumber, string otp) { // Twilio credentials string accountSid = "your_account_sid"; string authToken = "your_auth_token"; // Initialize Twilio client TwilioClient.Init(accountSid, authToken); // Message body string messageBody = $"Your OTP for verification is: {otp}"; // Send message via WhatsApp MessageResource.Create( from: new PhoneNumber("whatsapp:"), to: new PhoneNumber($"whatsapp:{toPhoneNumber}"), body: messageBody ); } }SendOtpViaWhatsAppmethod with the recipient's phone number and the OTP to send the OTP message.string recipientPhoneNumber = "recipient_phone_number"; string otp = "123456"; // Replace with your OTP var otpService = new OtpService(); otpService.SendOtpViaWhatsApp(recipientPhoneNumber, otp);