Share a record as a WhatsApp message
Purpose of this recipe
In this recipe, we’re going to add a WhatsApp button to the detail view form of one of our tables, allowing us to send the record contents as a WhatsApp message.
This works by simply opening a link to WhatsApp web. The link is formatted to specify recipient phone number and message to send. The link doesn’t actually send the message. It just puts it in the message box, ready for the user to click Send. This is a restriction imposed by WhatsApp to prevent sending messages by mistake (or by a malicious script) without the user reviewing them first.
For the sake of simplicity, we’ll assume that the phone number of the WhatsApp contact is stored in one of the fields of our table. But you can easily modify this recipe to prompt the user to enter any other phone number, rather than use the one stored in the record.
Files to edit
Edit (or create) the file hooks/tablename-dv.js
(where tablename
is the name of the
concerned table).
Please make sure to read the comments in the code below as they would help you understand and modify the code according to how your table and fields are structured.
|
|