Im using a function with the axios post call that will return a data that has share_link and shorten_url.
getShareURL = async () => {
try {
const body = {
email: this.props.user.email,
authentication_token: this.props.user.authentication_token,
context_name: this.state.contextText,
is_shared: true,
hvre: false,
is_mobile: true,
};
const res = await instance(this.props.user).post(
`api/shares/${this.state.asset_id}`,
body,
);
return res;
} catch (error) {
console.log('Share Failure Response', error);
throw error; // Propagate the error
}
};
I call this getShareURL() function to get the url, in the copyURL() function which gets called when the user presses the 'Copy Link' button, Im using 'npm i @react-native-clipboard/clipboard' package for copying.
copyURL = async () => {
try {
const shareURL = await this.getShareURL();
console.log('shareURL:', shareURL.data);
Clipboard.setString(shareURL.data.shorten_url);
showMessage(copiedToClipboard);
} catch (error) {
// Handle errors if any
console.error('Error copying URL:', error);
// Optionally show a message to the user indicating the error
showMessage({
message: 'Failed to copy URL. Please try again.',
type: 'danger',
});
}
};
Below is the console.log('shareURL:', shareURL.data);
{"context_hash": "jm6ol43vmv", "context_id": 552641, "id": 1063402, "link_hash": "vARXDnLn6PD1", "page_id": 1264456, "share_link": "https://2knzl3.placeholder.io/page/sales-paradigm-1_442fae08?custom_asset_token=LeYi2OKAqLysnvbzhkURJn8-46WmdmvnoCIk1NCWbOU&hvlk=vARXDnLn6PD1&org_tok=f5AMTsIaKtXP2Y5O-XpucQ&hvre=false", "shorten_url": "https://2knzl3.placeholder.io/s/P0oq97vk", "status": true, "video_token": "LeYi2OKAqLysnvbzhkURJn8-46WmdmvnoCIk1NCWbOU"}
What i want to achieve is when i paste this copied shorten_url into the gmail body, a thumbnail with the hyperlink 'watch video' with the shorten_url should be embedded into the gmail body (like the image below).
I tried to implement this by copying a html element as string and paste it in the gmail body and also tried to wrap the img and a element inside html and body element
const emailHTML = `
<img src="https://img.youtube.com/vi/dQw4w9WgXcQ/0.jpg" alt="Video Thumbnail" width="600" />
<br/>
<a href="${shareURL.data.shorten_url}" target="_blank" style="font-size: 18px; font-weight: bold; text-decoration: none; color: blue;">
▶ Watch Video
</a>
`;
Clipboard.setString(emailHTML);
But it just pasted this as text in the gmail body.
Can anyone help me implement this in react-native android?

