Why (&) sign is not showing in android default messaging app? - javascript

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);
}

Related

Whatsapp Click to Chat with emojis

Using Whatsapp 'Click To Chat' I'm able to send a message to a number, as expected.
But, I want to send some emojis in the prefilled message. It works well when I use a browser, but it doesn't work when I use a WebView inside an app (specifically a React Native app with a webview running the same site).
The problem:
For both, desktop browser or webView I use the same function and same encoding (encodeURI()), but
when the WebView calls the Whatsapp URL ("wa.me/...") the chat on Whatsapp shows all emojis as: �
Is it even possible to use emojis on Whatsapp Click to Chat? (I bet it is, since desktop browser works).
What can be happening on mobile/app?
Should I use some kind of character encoding, as unicode, UTF-8 (I already tested some, but no success)?
Here's the function that I'm using:
SendWhatsapp = function(message, number) {
number = LibGeral.NormalizeMobileNumber(number);
if (empty(message)) {
message = "";
}
var urlApiWhats = "https://wa.me/" + number + "?text=" + message;
urlApiWhats = encodeURI(urlApiWhats);
var a = document.createElement("a");
a.setAttribute("data-action", "share/whatsapp/share")
a.href = urlApiWhats;
window.document.body.appendChild(a)
a.click();
window.document.body.removeChild(a);
return true;
}
SendWhatsapp("I'm a message with emoji 😂", "xxxxxxxxx")
As said, inside the WebView from app, it calls the whatsapp url and opens the chat correctly, but the emoji is lost and just a question mark shows up. On Browser (Chrome, for example), it works very well and emoji appears (even on Chrome for mobile)
Also, even if I remove the encodeURI and pass the emoji 'directly', it still not working.
I'm pretty sure it was working some weeks ago...
This is how you should encode your URL:
const url = `https://api.whatsapp.com/send?phone=31612345678&text=${encodeURIComponent('Cheers from Vissie ⚡️')};
// returns: "https://api.whatsapp.com/send?phone=31612345678&text=Cheers%20from%20Vissie%20%E2%9A%A1%EF%B8%8F"
You can use https://wa.me/, I just used the other URL for this example. It's possible that in the browser it still gives �. But on your phone this should work.

How to send whatsapp message via Javascript

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).

JS OAuth 2.0 on Windows Phone 8.1

So, I'm trying to create a Gitter client for Windows Phone and to do so I need to use Bearer OAuth on their API. This process seems to result in a redirection to a gitter webpage (to get access tokens) and then it redirects to a web page specififed by my application. However obviously an APP is not a web page, so how am I supposed to get the returned temporary access token to use the API?
I've read a little bit about using ms-app://<security identifier> but it's all very fuzzy and little to no information seems to be about using it without using c#, but that's not what I'm looking for.
Any help would be greatly appreciated!
EDIT I just noticed this has been asked here oAuth 2.0 in Windows Phone 8.1 but hasn't been awnsered. Sorry for the duplication.
Seems that it was under my nose the whole entire time!
You can use Windows.Security.Authentication.Web.WebAuthenticationBroker.authenticateAndContinue(startURI, endURI);
(docs are mainly c# but here: http://msdn.microsoft.com/en-us/library/dn631755.aspx)
i.e
var redirect_uri = 'ms-app://<sid>';
var client_id = '<client id>';
// testing
var requestUri = new Windows.Foundation.Uri(
'https://<site>/?client_id=' + client_id + '&redirect_uri=' + redirect_uri
);
Windows.Security.Authentication.Web.WebAuthenticationBroker.authenticateAndContinue(requestUri, Windows.Foundation.Uri(redirect_uri));
app.addEventListener("activated", function (args) {
if (args.detail.kind == activation.ActivationKind.webAuthenticationBrokerContinuation) {
//take oauth response and continue login process
console.log(args.detail.webAuthenticationResult);
}
//Handle normal activiation...(hidden)
});
source: http://blog.stevenedouard.com/andcontinue-methods-for-windows-universal-apps/

Titanium pre-populate SMS body

I'm opening the native SMS composer in Android and want to pre-populate the SMS body. I tried...
Titanium.Platform.openURL('sms:?body=hello world!');
....but it adds hello world! to the contact field. Is there any way to add to the body?
for android, you can use intent to send sms...
Example
var intent = Ti.Android.createIntent({
action : Ti.Android.ACTION_VIEW,
type : 'vnd.android-dir/mms-sms',
});
intent.putExtra('sms_body', <body text>);
intent.putExtra("address", <number>);
try {
Ti.Android.currentActivity.startActivity(intent);
} catch (ActivityNotFoundException) {
Ti.UI.createNotification({
message : "Error"
}).show();
}
and for iphone you can use this module to send sms.

javascript mailto attachment not showing up

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>

Categories

Resources