/    Sign up×
Bounties /Pin to ProfileBookmark

Is it possible to send OTPs via WhatsApp without using third-party services?

+ 5,000
Copy linkTweet thisAlerts:
Oct 16.2023

Looking to send one-time passwords to users via WhatsApp, primarily because my target audience consists of older individuals who might not use email regularly. Is there a method to authorize a specific number (like an admin’s) to send these OTPs, similar to email-based OTP systems? I’d prefer to avoid third-party services with free plans if possible.

to post a answer
Back-endEngineerNode.js

2 Replies

Davinci•003 auto-replyNo, it's not possible to send OTPs via WhatsApp without using a third-party service. WhatsApp does not provide a direct API for developers to send messages. Instead, they have partnered with certain companies to provide this service.

One such service is the WhatsApp Business API, which is primarily meant for medium and large businesses to communicate with their customers at scale. However, it's not meant for mass messaging, promotions, or marketing.

To send an OTP via WhatsApp, you would need to use a third-party service that provides this functionality. These services usually have APIs that you can integrate into your application.

Here is a basic example of how you might use such a service's API:


const axios = require('axios');

const sendOtp = async (phoneNumber, otp) => {
const message = <span><code>Your OTP is: ${otp}</code></span>;

const response = await axios.post('https://api.thirdpartyservice.com/sendMessage', {
phone: phoneNumber,
body: message,
});

return response.data;
};

sendOtp('+1234567890', '123456')
.then(data =&gt; console.log(data))
.catch(error =&gt; console.error(error));


In this example, replace 'https://api.thirdpartyservice.com/sendMessage' with the actual API endpoint of the third-party service you are using. Also, you would need to replace '+1234567890' and '123456' with the actual phone number and OTP.

Remember to follow WhatsApp's policies and guidelines when sending messages to avoid being blocked or banned.

Was this helpful?

Copy linkTweet thisAlerts:
@felipechiericeNov 20.2023 — You could create your very own basic WhatsApp based OTP system. Following I'm sharing you a practical example on how to achieve that.

Write a back-end app (such with Node.js) sending WhatsApp messages through web.whatsapp.com using some sort of non-graphical web browsing tool, like cheerio.js.org. People often use that for web scrapping.

You basically want to simulate a UI interaction for typing some text into the message field and click the send button, and that's it. Well, actually you'll have a little challenge for allowing your "browser" to use your Wpp account by scanning the QR code, but you probably can bypass that just by manually setting the cheerio's requests cookies header with your personal browser's cookie for the Wpp website. That's just one option, but you can handle this part the way you find better for you.

And I think that's pretty much the most challenging part of the thing. Besides that, you'll just need to write the code for generating the OTP code for your messages, and the validation part.

I hope this gives you some north for starting your app. I'll be happy to assist on anything else in case you need :)
×

Success!

Help @cosmic spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...