Тёмный

Integrate Whatsapp API with Node.js 

manfra․io
Подписаться 1,4 тыс.
Просмотров 1,4 тыс.
50% 1

In this video, we're gonna learn how to integrate the Whatsapp API with a Node.js project, using Axios.
We're gonna learn how to send and create template messages, text messages, media messages, like images, how to upload an image to whatsapp cloud server so we can send to our contacts, and last, we're gonna learn how to generate a permanent API access token.
🔗 GitHub Repository:
github.com/man...

Опубликовано:

 

4 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 38   
@manfraio
@manfraio Месяц назад
The cost of using the official WhatsApp API is based on a conversation-based pricing model, where businesses pay per 24-hour conversation session with users. Prices range from approximately $0.005 to $0.07 for user-initiated conversations (session messages) and $0.02 to $0.14 for business-initiated ones (template messages), with the first 1,000 conversations per month being free.
@alexdioliver
@alexdioliver Месяц назад
Do not ever give up uploading new videos. You're a legend!
@manfraio
@manfraio Месяц назад
Thank you my friend. 🤜🏻🤛🏻
@aneeshbakshi7200
@aneeshbakshi7200 Месяц назад
This is why I love your channel. You come up with the best tutorials.
@manfraio
@manfraio Месяц назад
Thank you very much.🤜🏻🤛🏻
@bernardtowindo1949
@bernardtowindo1949 21 день назад
Very helpful, thanks alot.
@OnlyJavascript
@OnlyJavascript Месяц назад
you are amazing bro. but post more tuts. i learned stirpe integration from you and completed a project too. thanks a lot.
@manfraio
@manfraio Месяц назад
Thank you for the comment. Glad I could help.🤜🏻🤛🏻
@dharsanr6504
@dharsanr6504 Месяц назад
Kindly post full stack project tutorials that will be awesome👍
@manfraio
@manfraio Месяц назад
Yes, soon there will be full stack tutorials. Stay tuned my friend.🤜🏻🤛🏻
@smartdriver2990
@smartdriver2990 Месяц назад
Thanks for the useful content
@nobudev
@nobudev Месяц назад
best release time 🥳
@noelrobin8674
@noelrobin8674 Месяц назад
Hi bro can u do a complete node js tutorial for an app like food delivery app but explained in way that beginners can understand
@manfraio
@manfraio Месяц назад
Yes, soon we’re gonna upload entire project tutorials. Delivery app is one of them. Stay tuned!🤜🏻🤛🏻
@noelrobin8674
@noelrobin8674 Месяц назад
@@manfraio Thank you so much man looking forward to it !! 🔥🔥🔥
@innovateignite-753
@innovateignite-753 2 дня назад
Hi! Thank you for video! very informative! What if we want to send verification code for the user? In such a case the user won't answer, we must send the code as a first message. Do you have any idea how to implement this?
@manfraio
@manfraio 2 дня назад
Thank you for the comment. You can create a template message with a variable that is gonna be the verification code. Just like on the video, instead of sending the user name on the variable , you send the code. Does that make sense?
@innovateignite-753
@innovateignite-753 2 дня назад
@@manfraio Yes! Awesome! This way I don't need a Twillio in order to send just verification codes;) Thank you!
@innovateignite-753
@innovateignite-753 2 дня назад
@@manfraio Other question, adding my own phone number to sending messages through Whatsapp, can I use the same number on my phone?
@manfraio
@manfraio 2 дня назад
The WhatsApp Business API requires you to register a dedicated WhatsApp Business number that is separate from your personal WhatsApp number.
@09avishkargaikwad71
@09avishkargaikwad71 3 дня назад
I'm not able to select the test phone numbers. In your case the test phone is automatically generated but that's not same in my case. Can you provide any guidance?
@manfraio
@manfraio 3 дня назад
You mean the test number that whatsapp generated for you to use to send messages or the phone number you add, to send to that number?
@maged_sar7an
@maged_sar7an 2 дня назад
​@manfraio All of them please 😢
@maheshkumar-dn6of
@maheshkumar-dn6of 12 дней назад
good, how can I send document(pdf) along text message
@manfraio
@manfraio 12 дней назад
Use the upload function to upload the pdf file to whatsapp server: async function uploadFile(filePath) { const data = new FormData() data.append('messaging_product', 'whatsapp') data.append('file', fs.createReadStream(filePath) data.append('type', 'application/pdf') const response = await axios({ url: 'graph.facebook.com/v20.0/phone_number_id/media', method: 'post', headers: { 'Authorization': `Bearer ${process.env.WHATSAPP_TOKEN}` }, data: data }) return response.data.id } Then call the uploadFile function and send a message along with the file: async function sendPDFFile() { const pdfFileId = await uploadFile(filePath) const response = await axios({ url: 'graph.facebook.com/v20.0/phone_number_id/messages', method: 'post', headers: { 'Authorization': `Bearer ${process.env.WHATSAPP_TOKEN}`, 'Content-Type': 'application/json' }, data: JSON.stringify({ messaging_product: 'whatsapp', to: 'phone_number', type: 'document', document: { id: pdfFileId, caption: 'This is message', filename: 'any_filename' } }) }) console.log(response.data) }
@SathishM-n8i
@SathishM-n8i 10 дней назад
can we create a chatbot from Whatsapp API with Node.js ?
@manfraio
@manfraio 10 дней назад
Yes. You would need to create a webhook on your server to listen for incoming messages, and configure this webhook on your whatsapp business platform: // Webhook to receive messages from WhatsApp app.post('/webhook', (req, res) => { const webhookEvent = req.body; // Check if this is a message event if (webhookEvent.entry && webhookEvent.entry[0].changes && webhookEvent.entry[0].changes[0].value.messages) { const messageEvent = webhookEvent.entry[0].changes[0].value.messages[0]; const from = messageEvent.from; // The user's phone number const messageText = messageEvent.text.body; // The message content // Chatbot logic to respond to the message let responseMessage; // Basic chatbot responses (you can expand this logic) if (messageText.toLowerCase().includes('hello')) { responseMessage = 'Hello! How can I assist you today?'; } else if (messageText.toLowerCase().includes('price')) { responseMessage = 'Our products range from $10 to $100. How can I help with pricing?'; } else if (messageText.toLowerCase().includes('bye')) { responseMessage = 'Goodbye! Have a great day!'; } else { responseMessage = 'Sorry, I did not understand that. Can you please rephrase?'; } // Send the response back to the user sendMessage(from, responseMessage); } // Send a 200 OK response back to WhatsApp res.sendStatus(200); }); // Verification route to verify the webhook with WhatsApp app.get('/webhook', (req, res) => { const verifyToken = process.env.VERIFY_TOKEN || 'your_verify_token'; const mode = req.query['hub.mode']; const token = req.query['hub.verify_token']; const challenge = req.query['hub.challenge']; // Validate the webhook token if (mode && token === verifyToken) { console.log('Webhook Verified'); res.status(200).send(challenge); } else { res.sendStatus(403); } });
@insidedocumentary3162
@insidedocumentary3162 Месяц назад
Bro how can i add multiple number you didn't tell that
@manfraio
@manfraio Месяц назад
You have to loop inside an array of numbers. Till today the api only allow to send to one number.
@manfraio
@manfraio Месяц назад
Here’s an example: const phoneNumbers = ['1234567890', '0987654321', '1123456789']; // Message you want to send const messageText = 'Hello from WhatsApp via Node.js!'; // Loop through each phone number and send a message phoneNumbers.forEach(async (phoneNumber) => { try { // Send the message const response = await axios.post( apiURL, { messaging_product: 'whatsapp', to: phoneNumber, type: 'text', text: { body: messageText } }, { headers: { 'Authorization': `Bearer ${accessToken}`, 'Content-Type': 'application/json' } } ); console.log(`Message sent to ${phoneNumber}:`, response.data); } catch (error) { console.error(`Failed to send message to ${phoneNumber}:`, error.response ? error.response.data : error.message); } });
@insidedocumentary3162
@insidedocumentary3162 Месяц назад
@@manfraio Bother For Production level I want to send message on any Whatsapp like through my postmen, i take that number through user and send messages to that number is it possible?
@manfraio
@manfraio Месяц назад
@insidedocumentary3162 yes, but you cannot send any message. You have to send an template
@insidedocumentary3162
@insidedocumentary3162 Месяц назад
@@manfraio Yes i should send Template now is there any setting i have to do on face portal, 2nd the code you provide is enough to send Template message to anyone without adding there number in Facebook Developer Test Number list
Далее
Node.js Doesn’t Suck Anymore
16:59
Просмотров 116 тыс.
How to integrate PayPal API with Node.js
51:55
Просмотров 8 тыс.
How Many Twins Can You Spot?
00:17
Просмотров 20 млн
40 APIs Every Developer Should Use (in 12 minutes)
12:23
How to Send Media Files with WhatsApp Business API
15:47
WhatsApp Tech Provider - RegnSteps
29:02
Просмотров 2,3 тыс.
Node.js is a serious thing now… (2023)
8:18
Просмотров 651 тыс.
Exploring the HTML Dialog Element
21:03
Просмотров 140