Issue using react's package Linking to send automatic messages - javascript

i'm having an issue trying to use the {Linking} package. I'd like to send a text message to an specific number, like in the following code:
import { Linking } from ‘react-native’;
WhatsApp = (text, phone) => {
Linking.openURL(`whatsapp://send?text=${text}&phone=${phone}`);
}
But it happens that the message gets written in the App's text field, but I still need to press the 'send' button in order to really deliver my message. Does anybody know how to fix it? (send the message without having to press the button?)

Try this way:
WhatsApp = () => {
let msg = 'type something';
let phoneWithCountryCode = 'xxxxxxxxxx';
let mobile = Platform.OS == 'ios' ? phoneWithCountryCode : '+' + phoneWithCountryCode;
if (mobile) {
if (msg) {
let url = 'whatsapp://send?text=' + msg + '&phone=' + mobile;
Linking.openURL(url).then((data) => {
console.log('WhatsApp Opened');
}).catch(() => {
alert('Make sure WhatsApp installed on your device');
});
} else {
alert('Please insert message to send');
}
} else {
alert('Please insert mobile no');
}}
Please Note: send + in front of phone with country if opening in android

Related

How to add the value from an input box to an array and then output its contents?

How can I go about adding the value of an input box into an array and then display the contents of that array?
This is what I've come up with and I'm not sure why it's not working - the console.log doesn't post anything to the console, either.
var user = user;
if (!user) {
user = prompt('Please choose a username:');
if (!user) {
alert('Your name has been set to "Anonymous"');
} else {
alert('Your name has been set to "'+ user +'"');
}
}
var items = [];
function userArray() {
items.push(user);
return false;
console.log(items);
}
socket.on('onlineUsers', function (data) {
$('.dispUser').html(items);
});
The rest of the code in the file is below, just in case it helps... (changed the return statement, as per the first answer)
var user = user;
if (!user) {
user = prompt('Please choose a username:');
if (!user) {
alert('Your name has been set to "Anonymous"');
} else {
alert('Your name has been set to "'+ user +'"');
}
}
var items = [];
function userArray() {
items.push(users);
console.log(items);
return false;
}
socket.on('onlineUsers', function (data) {
$('.dispUser').html(items);
});
//Counts the number of users online
socket.on('count', function (data) {
$('.user-count').html(data);
});
//Receives messages and outputs it to the chat section
socket.on('message', function (data) {
$('.chat').append('<p><strong>' + data.user + '</strong>: ' + data.message + '</p>');
$('.chat').scrollTop($('.chat').height());
});
//SENDING OF THE MESSAGE
//Submit the form through HTTPS
$('form').submit(function (e) {
e.preventDefault();
// Retrieve the message from the user
var message = $(e.target).find('input').val();
// Send the message to the server
socket.emit('message', {
user: user || 'Anonymous',
message: message
});
// Clears the message box after the message has been sent
e.target.reset();
$(e.target).find('input').focus();
});
Answer
Your implementation is fine, but you have a bug which is preventing it from working as you've described.
The call to console.log(items) does not print anything, because that line of code never runs.
When you return from a function, the subsequent lines of code will not be ran. You should return as the last line within your function, or wrap it in a conditional.
For example:
function userArray() {
items.push(user);
console.log(items);
return false;
}
How to debug
Learning the techniques to figure this issue out yourself is an invaluable tool. You can leverage a debugger, such as the Chrome Devtools, to add breakpoints to your code. These will allow you to stop execution on a particular line, view the value of variables, and step through the remaining lines of code.
Doing so would make it clearly visible that the line of code is never running.
Find more details here: https://developers.google.com/web/tools/chrome-devtools/javascript

Twitch Ban Checker

can you help me with my Twitch Ban Checker
it worked a few months ago, but something is wrong now
maybe someone can give me a tip why it doesn't work anymore
I wrote this Twitch Ban Checker which, after entering the username, gives an answer whether you were banned on Twitch or not
the app is also on codepen https://codepen.io/olthoffs/pen/zqxbWW
var check_user = function (user) {
$(".description").fadeOut(20)
$.getJSON('https://api.twitch.tv/kraken/users/' + encodeURIComponent(user) + '?callback=?').done(function (data) {
if (/.+is unavailable$/.test(data.message)) { // Ban Check
var message = 'It looks like you were banned from twitch, please open a ticket via the '
message += '<a target="_blank" href="https://help.twitch.tv/customer/portal/emails/new?interaction[name]=' + user + '">official twitch support</a> '
message += 'site in order to see why you were banned.<br />'
message += '<span>TwitchTips cannot and will not help with your appeal</span>'
form_result('fail', message)
} else if (/.+is not available on Twitch$/.test(data.message) || /.+does not exist$/.test(data.message)) { // JTV/Nonexistant Check
var message = 'That account is either not a Twitch account or it does not exist.'
form_result('warn', message)
} else {
var message = 'The account provided does not seem to be banned on Twitch. '
message += 'If you\'re seeing a message telling you that you\'re blocked from Twitch, '
message += 'try disabling any VPN, proxy, or extension which re-routes traffic from your browser.<br/><br/>'
message += 'Got multiple accounts? Try checking those too because Twitch bans can be IP based.<br/><br/>'
message += 'If after doing so you are still getting the same error, '
message += 'your ISP may have provided your modem with a previously banned IP address. '
message += 'You can <a style="color: #fff" href="https://help.twitch.tv/customer/portal/emails/new?interaction[name]=' + user + '" target="_blank"><strong>open a ticket</strong></a> with Twitch to check.'
form_result('success', message)
}
}).fail(function () {
form_result('warn', 'The Twitch API appears to have returned an invalid response. Twitch may be having issues at the moment.')
})
}
var form_result = function (type, message) {
if (type === 'success') {
var title = "All is well!"
} else if (type === 'warn') {
var title = "Hmm, That's not right!"
} else {
var title = "Oh dear!"
}
$('.result').attr('class', 'result')
$('.result').html('<h3>' + title + '</h3>' + message)
$('.result').addClass(type)
$(".result").fadeIn()
}
$(document).ready(function () {
$('#ban-check').submit(function (e) {
e.preventDefault()
})
$('#ban-check').keyup(function (e) {
if (e.keyCode !== 13) {
return
}
e.preventDefault()
var user = $('#ban-check input').val()
window.location.hash = '#' + user
check_user(user)
})
var hash = location.hash
if (hash) {
var user = hash.substr(1)
$('#ban-check input').val(user)
check_user(user)
}
})
GET https://api.twitch.tv/kraken/users
(with client-id in the header)
returns:
{
"error": "Gone",
"status": 410,
"message": "It's time to kick ass and serve v3... and I'm all outta v3. See https://dev.twitch.tv/docs"
}
You might need to switch to helix, and go through OAuth flow.

Access headers/queryparams from a WebView from Nativescript

I am currently working on a mobile app with Nativescript. So, I do have a WebView in the main page to log in with Spotify. After the login I have to retrieve headers/queryparams from the page in the WebView. Is this possible and if, how do I do that?
You can register the loadFinishedEvent and check for the URL to get the queryparameters that are returning back to you. I am doing the same for third party login.
webViewLoaded(args) {
const webview: WebView = <WebView>args.object;
webview.on(WebView.loadFinishedEvent, (webargs: LoadEventData) => {
let message;
if (!webargs.error) {
if (webargs.url.toLowerCase().indexOf('spotity') > -1) {
//Read the parameters and navigate
}
message = 'WebView finished loading of ' + webargs.url;
} else {
message = 'Error loading ' + webargs.url + ': ' + webargs.error;
}
});
}

A complete example for a WebRTC datachannel with manual signaling

I'm really struggling to get a complete example of a WebRTC datachannel example that I can copy/paste and it works.
I would like a JavaScript example of WebRTC datachannel with manual signaling, i.e., when the example loads, it provides the Signaling data in one text box.
I copy data manually (highlight, copy) and paste it in the peer's window which has a text box to accept that signaling data. I believe there needs to be an "answer" in the signaling data, so there need to be corresponding text boxes waiting for that input as well.
Could the example use Google's free STUN server, please?
I get really confused with bit by bit examples. I want one file, please, that contains the HTML and JavaScript (no CSS or jQuery, please). It is enough for the code to work on Chrome only.
Here it is. Click the blue button below in two different tabs/windows/browsers/machines:
const output = document.getElementById('output');
const config = {
iceServers: [{
urls: "stun:stun.1.google.com:19302"
}]
};
const pc = new RTCPeerConnection(config);
const dc = pc.createDataChannel("chat", {
negotiated: true,
id: 0
});
const log = msg => output.innerHTML += `<br>${msg}`;
dc.onopen = () => chat.select();
dc.onmessage = e => log(`> ${e.data}`);
pc.oniceconnectionstatechange = e => log(pc.iceConnectionState);
chat.onkeypress = function(e) {
if (e.keyCode != 13) return;
dc.send(chat.value);
log(chat.value);
chat.value = "";
};
async function createOffer() {
button.disabled = true;
await pc.setLocalDescription(await pc.createOffer());
pc.onicecandidate = ({
candidate
}) => {
if (candidate) return;
offer.value = pc.localDescription.sdp;
offer.select();
answer.placeholder = "Paste answer here. And Press Enter";
};
}
offer.onkeypress = async function(e) {
if (e.keyCode != 13 || pc.signalingState != "stable") return;
button.disabled = offer.disabled = true;
await pc.setRemoteDescription({
type: "offer",
sdp: offer.value
});
await pc.setLocalDescription(await pc.createAnswer());
pc.onicecandidate = ({
candidate
}) => {
if (candidate) return;
answer.focus();
answer.value = pc.localDescription.sdp;
answer.select();
};
};
answer.onkeypress = function(e) {
if (e.keyCode != 13 || pc.signalingState != "have-local-offer") return;
answer.disabled = true;
pc.setRemoteDescription({
type: "answer",
sdp: answer.value
});
};
pc.onconnectionstatechange = ev => handleChange();
pc.oniceconnectionstatechange = ev => handleChange();
function handleChange() {
let stat = 'ConnectionState: <strong>' + pc.connectionState + '</strong> IceConnectionState: <strong>' + pc.iceConnectionState + '</strong>';
document.getElementById('stat').innerHTML = stat;
console.log('%c' + new Date().toISOString() + ': ConnectionState: %c' + pc.connectionState + ' %cIceConnectionState: %c' + pc.iceConnectionState,
'color:yellow', 'color:orange', 'color:yellow', 'color:orange');
}
handleChange();
<p id=stat></p>
<button id="button" onclick="createOffer()">Offer:</button>
<textarea id="offer" placeholder="Paste offer here. And press Enter"></textarea> Answer: <textarea id="answer"></textarea><br> Chat: <input id="chat"><br>
<pre id="output">Chat: </pre>
Then follow these steps:
In Window A, press the Offer button and copy the offer to the
clipboard.
In Window B, paste that offer into "Paste offer here" and hit the Enter key.
Copy the answer that appears after a few seconds.
Return to window A and paste that answer where it says "Paste answer here" and hit Enter.
You should now see a message saying you're "connected". Type in the chat box to chat!
If you and a friend exchange the offer/answer somehow, you now have a direct peer-to-peer connection. This should work around the world (modulo symmetric NAT routers); no data server involved.

Uncaught ReferenceError: web3 is not defined at window.onload

I'm trying to get my first dapp working; I know I'm close, but keep running into a problem with web3.
I am working on Windows 10, running a testrpc node via PowerShell. I used truffle to set up my folders & sample files, then compile and migrate.
I don't think I changed anything from the app.js file built by truffle... here is that code:
var accounts;
var account;
function setStatus(message) {
var status = document.getElementById("status");
status.innerHTML = message;
};
function refreshBalance() {
var meta = MetaCoin.deployed();
meta.getBalance.call(account, {from: account}).then(function(value) {
var balance_element = document.getElementById("balance");
balance_element.innerHTML = value.valueOf();
}).catch(function(e) {
console.log(e);
setStatus("Error getting balance; see log.");
});
};
function calcPremium() {
var premium = parseInt(document.getElementById("benefit").value)/10000;
document.getElementById("monthlyPremium").innerHTML = " Monthly Premium: $"+premium.toFixed(2);
};
function sendCoin() {
var meta = MetaCoin.deployed();
var amount = parseInt(document.getElementById("monthlyPremium").value);
var receiver = document.getElementById("receiver").value;
setStatus("Initiating transaction... (please wait)");
meta.sendCoin(receiver, amount, {from: account}).then(function() {
setStatus("Transaction complete!");
refreshBalance();
}).catch(function(e) {
console.log(e);
setStatus("Error sending coin; see log.");
});
};
window.onload = function() {
web3.eth.getAccounts(function(err, accs) {
if (err != null) {
alert("There was an error fetching your accounts.");
return;
}
if (accs.length == 0) {
alert("Couldn't get any accounts! Make sure your Ethereum client is configured correctly.");
return;
}
accounts = accs;
account = accounts[0];
refreshBalance();
});
}
I'm able to open the html file in a Chrome browser, with the MetaMask plugin enabled. However, it seems I'm unable to interact with the contracts in any way, due to the web3 error issue. The exact message is this post's subject line.
Thanks in advance for any help or guidance!
Could you please try it and see . I think the onload is giving the issue.
$(window).load function() {
web3.eth.getAccounts(function(err,accs) {
if (err != null) {
alert("There was an error fetching your accounts.");
return;
}
if (accs.length == 0) {
alert("Couldn't get any accounts! Make sure your Ethereum client is configured correctly.");
return;
}
accounts = accs;
account = accounts[0];
refreshBalance();
});
}

Categories

Resources