Hi I would like to know if there is something to send a whatsapp message using javascript or something I was searching but I did not find any new post. This is not for any special purpose. I found this but it only works if you have whatsapp web. I was thinking on clicking on a link to send a default message to a default number
Send Message
Just make use of this function in web browser to get it running as you want.
Note: You need to run the code manually through browser console with an opened conversation in WhatsApp
(web version).
function sendMessage(message){
const mainEl = document.querySelector('#main')
const textareaEl = mainEl.querySelector('div[contenteditable="true"]')
if(!textareaEl) {
throw new Error('There is no opened conversation')
}
textareaEl.focus()
document.execCommand('insertText', false, message)
textareaEl.dispatchEvent(new Event('change', { bubbles: true }))
setTimeout(() => {
(mainEl.querySelector('[data-testid="send"]') || mainEl.querySelector('[data-icon="send"]')).click()
}, 100)
}
Ref: https://github.com/Matt-Fontes/SendScriptWhatsApp/blob/main/shrekSendScript.js
I find this way is a better way to send a msg to WhatsApp unknowing number.
// github: omar-bakhsh
function send_handle(){
let num=document.getElementById("number").value;
let msg= document.getElementById("msg").value;
let name= document.getElementById("name").value;
var win = window.open(`https://wa.me/${num}?text=I%27m%20api%20msg%20hello%20${name}%20friend%20${msg}`, '_blank');
// win.focus();
}
<div>
<h3>whatsapp send app </h3>
<h6>add number without space like 17272912606 not <strike>+1 (727) 2912606 </strike></h6>
<input id="number" type="numric" placeholder="phone 966506666666" >
<input id="name" type="text" placeholder="name" >
<input id="msg" type="text" placeholder="type msg" >
<button onclick="send_handle()">send</button>
You can do this:
Send Message
Whatsapp dosen't support sending messages from the PC. Every message has to come from a Phone. Whatsapp web is just redirecting the messages to your phone wich is then sending the message. If you use their api you only can let users send a message to any number via Whatsapp using their phone. To predetermine the message use:
https://api.whatsapp.com/send?phone=whatsappphonenumber&text=urlencodedtext
more: https://faq.whatsapp.com/en/android/26000030/?category=5245251
On the WhatsApp developers hub, they demonstrated a walkthrough guide on how to opt-in for a developer account on meta, and create an app so can make api calls if you want to use WhatsApp programmatically,
Short version:
Register as a Meta Developer
Enable two-factor authentication for your account
Create a Meta App: Go to developers.facebook.com > My Apps > Create App.
Select the "Business" type and follow the prompts on your screen.
Scroll down to find the "WhatsApp" product and click Set up.
Select an existing Business Manager, if you don't the wizard will guide you to create one.
Next screen will show you a demo.
If you need a listener when your number receive a message or reply, you should register webhooks.
Add your phone number to use it programmatically. and it shouldn't be connected with WhatsApp at all, neither personal or business.
for more details follow the getting started guide:
https://business.whatsapp.com/developers/developer-hub
It's impossible to do it with HTML link. Whatsapp has no official API. But you can find (or write it by yourself) some script to emulate user actions on the site web.whatsapp.com. For example, this one (I did not test it).
Related
I am using sms method in html to send my message (Hello & Welcome) through android default messaging app.
Here is my code:
<a href="sms:001234567890?body=Hello%20%26%20Welcome">
<button>
Say Hello,
</button>
</a>
I have expect Hello & Welcome
But android default messaging app is only showing Hello not & Welcome (full message body)
I have also tried:
%26&&&&
But it's still not showing.
Try this
<a href="sms:001234567890?body=Hello+%26+Welcome">
Refer this
I think you have discovered a bug!
Note the differences here (&, %):
IOS:
Send an SMS
Android:
Send an SMS
You can combine these to support both like so:
Send a SMS message
Now... This has been quite a pain. I've even been able to crash Android Messenger... I am able to find little to no documentation about SMS links.
Specifically there is problems with &. The below i am inserting an exclamation mark and it is working fine.
Send a SMS message
You can use this method for encode when sending message and decode to show by given methods.
private String encodeMessage(String message) {
message = message.replaceAll("&", ":and:");
message = message.replaceAll("\\+", ":plus:");
return StringEscapeUtils.escapeJava(message);
}
private String decodeMessage(String message) {
message = message.replaceAll(":and:", "&");
message = message.replaceAll(":plus:", "+");
return StringEscapeUtils.unescapeJava(message);
}
I have a live score display website which is implemented with Google's channel API to push live score updates to the browser. Since Google is shutting down the channel API, I have to move to Firebase Cloud Messaging.
When I migrated to FCM, I had to add a service worker javascript file (firebase-messaging-sw.js). Whenever a score update is pushed to the browser, if the user is in another browser tab or the user has closed my web page tab, A notification appears to the user.
I don't need this notification and I want to disable it. Also, when user moves to another browser tab, I want to prevent the push message from going into the service worker and route it to my web page, so that when user returns to the tab again, the latest score is updated in the webpage.
Is there any way to achieve this?
You should pass a parameter (depends what you need to do) in the body of message like this:
$msg = [
'title' => pushTitle,
'body'=> pushBody,
'icon'=> icon.png,
'image'=> image.png,
'active'=> 1
];
The above is PHP but is also working in the same way-idea in any programming language. If you use Firebase then you should use cloud functions.
then in your js file:
messaging.setBackgroundMessageHandler(function(payload) {
console.log('Received background message', payload);
if(payload.data.active == 1){
return;
}
var notificationTitle = payload.data.title;
var notificationOptions = {
body: payload.data.body,
icon: payload.data.icon,
image: payload.data.image
};
return self.registration.showNotification(notificationTitle, notificationOptions);
});
If I had your code(what did you have done until now) I would gave you an exact answer.
If you have more questions don't hesitate to ask.
I implement push notification using this totarial. Now I want to send a notification from a website using server C# code or simply with a javascript code but the following link only implement sending notification using node:
var gcm = require('node-gcm');
var message = new gcm.Message();
//API Server Key
var sender = new gcm.Sender('AIzaSyCDx8v9R0fMsAsjoAffF-P3FCFWXlvwLhg');
var registrationIds = [];
// Value the payload data to send...
message.addData('message',"\u270C Peace, Love \u2764 and PhoneGap \u2706!");
message.addData('title','Push Notification Sample' );
message.addData('msgcnt','3'); // Shows up in the notification in the status bar
message.addData('soundname','beep.wav'); //Sound to play upon notification receipt - put in the www folder in app
//message.collapseKey = 'demo';
//message.delayWhileIdle = true; //Default is false
message.timeToLive = 3000;// Duration in seconds to hold in GCM and retry before timing out. Default 4 weeks (2,419,200 seconds) if not specified.
// At least one reg id required
registrationIds.push('APA91bwu-47V0L7xB55zoVd47zOJahUgBFFuxDiUBjLAUdpuWwEcLd3FvbcNTPKTSnDZwjN384qTyfWW2KAJJW7ArZ-QVPExnxWK91Pc-uTzFdFaJ3URK470WmTl5R1zL0Vloru1B-AfHO6QFFg47O4Cnv6yBOWEFcvZlHDBY8YaDc4UeKUe7ao');
/**
* Parameters: message-literal, registrationIds-array, No. of retries, callback-function
*/
sender.send(message, registrationIds, 4, function (result) {
console.log(result);
});
I want to send notification automatically using website or something like this (I want to scheduling sending notification in some times for remind drug time to patient).
In addition, I found this : pubnub for sending notification but unfortunately, it's not work correctly. Pubnub demo doesn't work.
How can I do this? Please help me.
Can you give either of these a try if you're writing C# on the server side? :)
Azure Notification Hub
PushSharp
Personally I'd write a Windows Service that runs a loop to poll the database for any notifications it needs to send out, sends it to Azure Notification Hub or AWS Push Notifications, sleeps for awhile, and then repeats the process.
You don't want to do it on the client side of a web page because the only way the code could ever run is if you had a web browser open all the time pointing to the page.
The website im trying to login to has the following username field
<input type="text" id="inputEmailHandle" name="inputEmailHandle" value>
Im using Zombie Headless browser and nodejs, Zombie cannot find the input field named "inputEmailHandle" so i cannot automatically log in, i think its because of the value>
is there anyway i can get around it? or does anyone know a good way to do this with javascript and nodeJS?
ps the website im trying to log into is craigslist
Here's the code
var Browser = require("zombie");
var assert = require("assert");
browser = new Browser()
browser.visit("https://accounts.craigslist.org", function () {
browser.
fill("inputEmailHandle", "person#email.com").
fill("inputPassword", "password").
pressButton("button", function() {
console.log("LOGGED INNNNN!!!");
assert.ok(browser.success);
})
});
The website is running iso-8859-1 encoding, which is apparently not supported by zombie... that is why its not finding anything
i'm trying to create a small web app wherein in one form, the user may type in certain parameters as part of the message, then after he hits a button, it will show an Outlook (depends on his default email client) email client popup with all the details he placed.. and then it will include an attachment.
the javascript code looks like this:
function submitReport()
{
var remarks = document.getElementById('remarks').value;
if(remarks != '')
body += 'Remarks: '+remarks;
var href = 'mailto:bug_support#emailadd.com?subject=[Bug Report] '+menu_path+'&body='+body;
href += '&attachment="C:\\debug.log"';
var form = DomUtils.createForm();
form.setAttribute('action', href);
form.submit();
}
i tried alerting the "href" variable and it shows:
mailto:bug_support#emailadd.com?subject=[Bug Report]&body=message_bodyReport Type: MonthlyStart Date: 2010-05-01 00:00:00End Date: 2010-05-31 23:59:59&attachment="C:\debug.log"
and surely an outclient popsup with all the subject, recepient email address, body..
but no attachment. anybody encountered this before? :(
the outlook used here is 2007..
if i run the web app in IE, it actually says an error
"The command line argument is not valid. Verify the switch you are using."
any ideas?
There is no way for a web page to cause a browser to open the user's email client with a file pre-attached from the hard disk.
Use a form and process it server side, or provide simple instructions along the lines of:
<p>Send an email to foo#example.com
and attach your log file.</p>