This topic is locked

Send a Whatsapp message to a Whatsapp User or Whatsapp Group - Part 1of2

2/6/2024 11:57:02 AM
PHPRunner Tips and Tricks
F
Farhaad author

Do you need to send a Whatsapp message to a Whatsapp User or Whatsapp Group

This is not the ideal method to code but its was a proof of concept.
Im sure that many here will find a better way of doing the same with neater and cleaner coding.

Lets assume you are receiving a request from your customer regarding utility services from the local government.
The customer fills in a form tell you he has no power at his address.
You offering a service by informing the appointed service provider to help the customer.
Now you want to communicate your reference number back to the customer via Whatsapp.

The MySQL table is very basic.

SELECT

id,

/* customer input form */
date_today,
type_i,
severity,
street_address,
notes,
customer_name,
customer_cellular_nr,
reference_nr,

/* Whatsapp fields to send message to customer via Whatsapp */
whatsapp_customer_name,
whatsapp_customer_cellular_nr,
whatsapp_customer_message,
whatsapp_customer_share_link,

/* Whatsapp fields to send message to multiple customers or groups via Whatsapp */
whatsapp_customer_group_name,
whatsapp_customer_group_id_nr,
whatsapp_customer_message,
whatsapp_customer_share_link,

FROM service_delivery

MySQL Code

/* Whatsapp fields to send message to customer via Whatsapp /
CONCAT(customer_name) AS whatsapp_customer_name,
CONCAT('27',SUBSTRING(customer_cellular_nr,2)) AS whatsapp_customer_cellular_nr,
/
'27' = country code, substring is used to remove the 1st number if there is a 0 in the customer cellular nr. Eamples: 0765260576 -> 765260576 /
/
Omit any zeroes, brackets, or dashes when adding the phone number in international format.
/ The result of this field will be 27765260576 /
CONCAT(
'Ref. Nr: ','<b>',reference_nr,'</b>','
',
'Severity: ','<b>',severity,'</b>','
',
'Incident: ','<b>',type_i,'</b>','
',
'Location; ','<em>', street_address,'</em>','
',
'Details: ','<b>', notes,'</b>','
',
'More Info.: ','<b>', '<a href="https://communityfirst.org.za'>https://communityfirst.org.za">Community'>https://communityfirst.org.za'>https://communityfirst.org.za">Community First</a>','</b>','
',
'Link: ','https://communityfirst.org.za'>https://communityfirst.org.za'
) AS whatsapp_customer_message,
/ I included a lot of HTML tags here, so that the data display in the view screen in a format that is readable. /
/ This is not the best way to code and not recommend but I did it as a proof of concept /
/ The thinking behind this was that if my link to Whatsapp didnt work i could just copy the formatted result and post into Whatsapp manually /
/ PS. Add the following code to this fields properties. View as --> Custom --> strip_tags() (this code strips the HTML tag in the view screen but the format remains /
CONCAT('https://wa.me/',CONCAT('27',SUBSTRING(reporters_contact_nr,2)), '/?text=','',
REGEXP_REPLACE(
CONCAT(
'Ref. Nr: ','<b>',reference_nr,'</b>','
',
'Severity: ','<b>',severity,'</b>','
',
'Incident: ','<b>',type_i,'</b>','
',
'Location; ','<em>', street_address,'</em>','
',
'Details: ','<b>', notes,'</b>','
',
'More Info.: ','<b>', '<a href="https://communityfirst.org.za'>https://communityfirst.org.za">Community'>https://communityfirst.org.za'>https://communityfirst.org.za">Community First</a>','</b>','
',
'Link: ','https://communityfirst.org.za'>https://communityfirst.org.za'
),
'(<[^>]>)|( )', ' '),'',
'&type=phone_number&app_absent=0') AS whatsapp_customer_share_link,
/
The pre-filled message will automatically appear in the text field of a chat. /
/
Use https://wa.me/whatsappphonenumber?text=urlencodedtext where whatsappphonenumber is a full phone number in international format and /
/
urlencodedtext is the URL-encoded pre-filled message. /
/
After clicking on the link, Whatsapp will open in your browser you’ll be shown a pre-filled message in the customer chat screen. /
/
All that is left for you to do is hit Send! /
/
PS. Set the fields properties as follows. Edit as --> Readonly. View as --> Hyperlink, (tick) open link in new browser, (tick) displa word "Share to Customer via Whatsapp" */

/* Whatsapp fields to send message to multiple customers or groups via Whatsapp */
whatsapp_customer_group_name,
whatsapp_customer_group_id_nr,
whatsapp_customer_message,
whatsapp_customer_share_link,

/ If you want the code for multiple customers or groups via Whatsapp urgently the just email me on farhaad@driversfriend.co.za /
/ If you not in a hurry i will be posting as soon as i get some free time /

Enjoy