Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
share-text-to-whatsapp
Advanced tools
A small JS utility library for sharing text content via WhatsApp or via the native sharing widget of your device.
A small JS utility library for sharing text content via WhatsApp or via the native sharing widget of your device.
$ npm install --save share-text-to-whatsapp
// or
$ yarn add share-text-to-whatsapp
This function uses WhatsApp's Click to Chat feature which allows you to begin a chat with someone without having their phone number saved in your phone's address book.
Click to Chat works on both phone and WhatsApp Web.
import { shareTextToWhatsApp } from 'share-text-to-whatsapp';
const message = 'Hello world';
shareTextToWhatsApp(message); // This will open up WhatsApp and you will be shown a list of contacts you can send your message to.
WhatsApp allows you to format selected text inside your messages.
_text_
*text*
For more information on formatting, see this guide.
Use template literals to create multi-line messages like the following below.
import { shareTextToWhatsApp } from 'share-text-to-whatsapp';
console.log(
getWhatsAppClickToChatLink(`
This is a multi-line text
how will it be handled
_this is italic_
*this is bold*
`)
);
Depending on the device, it invokes the native sharing mechanism of the device as part of the Web Share API.
import { shareTextViaNativeSharing } from 'share-text-to-whatsapp';
const data = {
message: 'Check out this website', // required
title: 'Awesome Website', // optional parameter
url: 'https://www.awesomeexample.com', // optional parameter
};
shareTextViaNativeSharing(data); // This will open up WhatsApp and you will be shown a list of contacts you can send your message to.
If the Web Share API is not supported by the users's browser, you can specify a fallback function as the second function argument.
import { shareTextViaNativeSharing } from 'share-text-to-whatsapp';
const data = {
message: 'Check out this website', // required
title: 'Awesome Website', // optional parameter
url: 'https://www.awesomeexample.com', // optional parameter
};
shareTextViaNativeSharing(data, () => {
// fallback function if native sharing is not supported
// for example, send the message via the Click to Chat feature instead
shareTextToWhatsApp(data.message);
});
Returns true
if the user's browser supports Web Share API for invoking the device native sharing mechanism.
import { hasNativeSharingSupport } from 'share-text-to-whatsapp';
hasNativeSharingSupport(); // returns true or false
As of August 2019, the Web Share API is supported by the following browsers. See caniuse.com for a more updated information.
Accepts a string
message and returns a link with a pre-filled message that will automatically appear in the text field of a chat.
This returned link will have either of the following format:
urlencodedtext
is the URL-encoded pre-filled message.
When clicking on the link, the user will be shown a list of contacts to send the message to.
import { shareTextViaNativeSharing } from 'share-text-to-whatsapp';
const message = 'Hello world';
getWhatsAppClickToChatLink(message); // https://wa.me?text=hello%20there || whatsapp://send?text=hello%20there
No. If the user does not have WhatsApp installed and native sharing is used, the user will have the other apps to choose from when sending the message either the device messaging app, via email, etc.
If using the Click to Chat feature, the user will be redirected to the WhatsApp download page in order to use it.
MIT © Ana Liza Pandac
FAQs
A small JS utility library for sharing text content via WhatsApp or via the native sharing widget of your device.
The npm package share-text-to-whatsapp receives a total of 0 weekly downloads. As such, share-text-to-whatsapp popularity was classified as not popular.
We found that share-text-to-whatsapp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.