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.
Related
I need to run my custom protocol twice but it doesn't work the second time, I got this error ( Not allowed to launch 'cutomProtocol' because user gesture is required. ) I tried to find a solution but I did not find any!
Same problem with chrome, firefox and edge.
I need to see this popup twice
window.location.href = 'my-protocol://${base64}';
and
customProtocolVerify(
`my-protocol://${base64}`,
() => {
// successCb: Callback function which gets called when custom protocol is found.
console.log('My protocol found and opened the file successfully..');
},
() => {
// failCb: Callback function which gets called when custom protocol not found.
console.log('My protocol not found.');
}
);
I tried with these two and didn't work
Clarification
I have a custom protocol.
My scenario:
check if it's installed successfully (I'm using customProtocolVerify method) and that method makes the launch if the protocol is found
run some APIs
launch the protocol again
My problem:
Step 3 doesn't work, I have the error on the console that says " Not allowed to launch... " and of course I can't see my popup to open my protocol.
I'm asking for help to make step 3 work
The only way to bypass this "bug" is to ask the user twice (or in a loop) by showing a OK alert or some sort of user confirm box.
My solution:
OpenLinkInExternalApp(Link);
alerty.alert('', { title: '', okLabel: 'Open Link' }, function () {
OpenLinkInExternalApp(Link);
});
The above code will open the external app, then a OK alert will pop up, after clicking OK, I call the same code again. Do this in a loop if needed.
TIP:
We guide our users to use split screen at this stage. This is where users can dock your web-app on the left and the external app on the right as an example.
Alert Box:
We user Alerty.js https://github.com/undead25/alerty#readme
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'm writing a simple Automator script in Javascript.
I want to send a key-code(or key-storke) to an OS X application that is not in front.
Basically, I want to run this code and do my things while the script opens a certain application, write text, and hit enter - all of this without bothering my other work.
I want something like this:
Application("System Events").processes['someApp'].windows[0].textFields[0].keyCode(76);
In Script Dictionary, there is keyCode method under Processes Suite.
The above code, however, throws an error that follows:
execution error: Error on line 16: Error: Named parameters must be passed as an object. (-2700)
I understand that the following code works fine, but it require the application to be running in front:
// KeyCode 76 => "Enter"
Application("System Events").keyCode(76);
UPDATE: I'm trying to search something on iTunes(Apple Music). Is this possible without bringing iTunes app upfront?
It's possible to write text in application that is not in front with the help of the GUI Scripting (accessibility), but :
You need to know what UI elements are in the window of your specific
application, and to know the attributes and properties of the
specific element.
You need to add your script in the System Preferences --> Security
& Privacy --> Accessibility.
Here's a sample script (tested on macOS Sierra) to write some text at the position of the cursor in the front document of the "TextEdit" application.
Application("System Events").processes['TextEdit'].windows[0].scrollAreas[0].textAreas[0].attributes["AXSelectedText"].value = "some text" + "\r" // r is the return KEY
Update
To send some key code to a background application, you can use the CGEventPostToPid() method of the Carbon framework.
Here's the script to search some text in iTunes (Works on my computer, macOS Sierra and iTunes Version 10.6.2).
ObjC.import('Carbon')
iPid = Application("System Events").processes['iTunes'].unixId()
searchField = Application("System Events").processes['iTunes'].windows[0].textFields[0]
searchField.buttons[0].actions['AXPress'].perform()
delay(0.1) // increase it, if no search
searchField.focused = true
delay(0.3) // increase it, if no search
searchField.value = "world" // the searching text
searchField.actions["AXConfirm"].perform()
delay(0.1) // increase it, if no search
// ** carbon methods to send the enter key to a background application ***
enterDown = $.CGEventCreateKeyboardEvent($(), 76, true);
enterUp = $.CGEventCreateKeyboardEvent($(), 76, false);
$.CGEventPostToPid(iPid, enterDown);
delay(0.1)
$.CGEventPostToPid(iPid, enterUp);
I am editing a javascript code[the code takes me directly to downloading the video to mp3] since the code provided by the website was not working..i tried editing on my own
This is the code below
javascript:(function() {if (location.href.indexOf('www.youtube.com') > -1) {var uri_enc = encodeURIComponent(location.href).replace(/https%3A%2F%2Fwww.youtube.com%2Fwatch/g,'');var uri_dec = decodeURIComponent(uri_enc);window.open("http://youtubeplaylist-mp3.com/" + uri_dec)}else{alert('sorry youcant');}}) ();
Now the problem here is, I have made a bookmark of this code in chrome, The intention of the bookmark is to run the code when I visit the youtube video page and press the bookmark button.
But for some reason the bookmark doesn't seem to work. so I opened up the console and checked the reason..here are the pictures below of the error..
in console this error comes
on further examining i find that %2F is getting detected as closing '/' so its not detecting the latter part
on further examining i find that %2F is getting detected as closing '/' so its not detecting the latter part
Because of that false detection my bookmark is not working.
However the good news is that if I copy paste the code to console directly and execute then it will work succesfully.
But that is too much work.:p for everyday use.
so help me fix the bookmark please.
UPDATE
Javascript is solved and bookmark is working...
Here below is the complete code..which works for single video and a playlist too..you just need to click on the bookmark when you are on the video page or the playlist page which will direct to download page...
javascript:(function() {if (location.href.indexOf('www.youtube.com') > -1) {var uri_enc = location.href.replace(/https:\/\/www.youtube.com\/watch|https:\/\/www.youtube.com\/playlist/g,'');window.open("http://youtubeplaylist-mp3.com/" + uri_enc);}else{alert('sorry youcant');}}) ();
I am still learning javascript so it took quiet time to understand the answers but thanks to both the coders who answered especially TigOldBitties who gave the complete code from which I understood what the mistake was...Have a nice day..
You need to escape the forward slashes so they don't close the regex
.replace(/https:\/\/www.youtube.com/, '')
LE: The complete answer is that now that you know that you can escape special characters you can drop the needless encoding and just use:
javascript:(function() {if (location.href.indexOf('www.youtube.com') > -1) {var uri_enc = location.href.replace(/https:\/\/www.youtube.com\/watch/g,'');window.open("http://youtubeplaylist-mp3.com/" + uri_enc);}else{alert('sorry youcant');}}) ();
No, it is not a bug.
Bookmarks point to URLs.
You happen to have encoded JavaScript into your URL … and a URL into your JavaScript.
You need to escape the / twice. Once for the http: URL and then again for the javascript: URL.
So / becomes %2F and that becomes %252F
I'm using Javascript (Cordova/PhoneGap Build) to get some profile pictures using the Facebook Graph API. Here is a sample code:
FB.api("/v1.0/" + tmp_fb_id + "/picture?redirect=0&height=" + pic_height + "&type=normal&width=" + pic_width, function (response) {
if (response && !response.error) {
var json_data = response.data;
$("#img-1").attr("src", json_data.url);
}
This worked fine until recently. On some phones, the image doesn't show up anymore, and I figured out it's because of the url format that I get from facebook. Some urls look like this:
https://scontent-a.xx.fbcdn.net/hprofile-xaf1/l/t31.0-1/c435.168.1177.1030/s320x320/219800_10150165625678127_6471352_o.jpg
And they are FINE on all phones. But sometimes, the response url that I get from facebook looks like this (notice the extra variables after .jpg):
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpf1/v/t1.0-1/c0.20.320.280/p320x320/10004054_10152380867008400_6911804500751766609_n.jpg?oh=f7845490992f046f29b99384f2c37022&oe=54855B4B&__gda__=1421641326_c476878a926031e9d295f33da3683d79
And these images do not show up on many Android Phones (it's a "?" as if the image is broken). If I remove the variables after "?", the image won't show up anymore (in the desktop browser it says "An error occurred while processing your request."), so it's definitely needed. Any idea what could be done to be able to show these images on ALL phones?