Ionic SocialSharing with pdf file for whatsapp - ionic-framework

I am using pdfMaker to create an object of type Document, I would like to send this file to a contact I have saved on Whatsapp, it would be something similar to using the shareViaWhatsAppToReceiver function using SocialSharing.
The file's attachment would already come in the message.
this.socialSharing.shareViaWhatsAppToReceiver(`+55 ${contact.phone}`, `PDF`,
null, this.pdfObj).then(async () => {
const toast = await this._toast.create({
message: 'Send success.',
duration: 3000
});
});
The way I am doing above does not work, I would like to send the document directly as a parameter so that the message on Whatsapp is attached.

Related

How to only open email app and attach a file?

I'm trying to only OPEN an email app i.e. Outlook, Gmail, etc. and with an attachment already attached. Ready for the user to write a subject and send it to someone. Again I'm not looking to send it automatically, only open the app with the attachment attached.
So far the only thing I found is this: https://pub.dev/packages/launchers
But I am getting an error message: "No implementation found for method send on channel GitHub.com/sunnyapp/launchers_compose"
Here is my code: I am at a loss. I feel like this should be an easy thing to do. P.S most email openers can open an email app but can't attach attachments. I also know this is for mobile only. Android and iOS.
final Email email = Email(
body: "This Email was Created by TRS to send an Excel File!",
subject: "$excelName",
recipients: [""],
attachmentPath: fullPath,
);
Iterable<String> platformResponse;
try {
final results =
await LaunchService().launch(composeEmailOperation, email);
print(results);
platformResponse = results.allAttempts.entries.map((entry) {
print("Provider = ${entry.key}\nResult = ${entry.value}");
return "P";
});
} catch (error, stack) {
print(error);
print(stack);
platformResponse = ["Error: $error"];
}
You can use https://pub.dev/packages/share_plus package:
String filename = './docs/myfile.xlsx'
Share.shareFiles([filename], text: 'This Email was Created by TRS to send an Excel File!');
This opens gmail or whatever app you have with attachment and text but this particular code only works on mobile, not on desktop. I

Google Assistant make GET request and reply with server response

I'd like to create an action in Google Assistant such that when a voice command is issued, the Assistant will make a GET request to a URL, like http://example.com/response.txt and just read out the plaintext response. How do I go about doing that?
You would need to create an Action using Actions Builder or Dialogflow.
This Action would start with a 'Default Welcome Intent' that you should connect it to a webhook:
This webhook can be written simply using a language like Node.js
import {conversation} from '#assistant/conversation'
const fetch = require('node-fetch')
const app = conversation()
const URL = 'http://example.com/response.txt'
app.handle('Default Welcome Intent', async conv => {
const apiResponse = await fetch(URL)
const text = await apiResponse.text()
conv.add(text)
})
Depending on whether you just want static information or not, you may want to then add a transition to 'end conversation' to close it out.

Flutter open whatsapp with text message

I want to open whatsapp from my Flutter application and send a specific text string. I'll select who I send it to when I'm in whatsapp.
After making some research I came up with this:
_launchWhatsapp() async {
const url = "https://wa.me/?text=Hey buddy, try this super cool new app!";
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
Which works ok ish, however there are two problems:
As soon as I make the text string into multi words it fails. So if I change it to:
_launchWhatsapp() async {
const url = "https://wa.me/?text=Hey buddy, try this super cool new app!";
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
Then the Could not launch $url is thrown.
I have whatsapp already installed on my phone, but it doesn't go directly to the app, instead it gives me a webpage first and the option to open the app.
Here is the webpage that I see:
Any help on resolving either of these issues would be greatly appreciated.
Thanks
Carson
P.s. I'm using the Url_launcher package to do this.
From the official Whatsapp FAQ, you can see that using "Universal links are the preferred method of linking to a WhatsApp account".
So in your code, the url string should be:
const url = "https://wa.me/?text=YourTextHere";
If the user has Whatsapp installed in his phone, this link will open it directly. That should solve the problem of opening a webpage first.
For the problem of not being able to send multi-word messages, that's because you need to encode your message as a URL. Thats stated in the documentation aswell:
URL-encodedtext is the URL-encoded pre-filled message.
So, in order to url-encode your message in Dart, you can do it as follows:
const url = "https://wa.me/?text=Your Message here";
var encoded = Uri.encodeFull(url);
As seen in the Dart Language tour.
Please note that in your example-code you have put an extra set of single quotes around the text-message, which you shouldn't.
Edit:
Another option also presented in the Whatsapp FAQ is to directly use the Whatsapp Scheme. If you want to try that, you can use the following url:
const url = "whatsapp://send?text=Hello World!"
Please also note that if you are testing in iOS9 or greater, the Apple Documentation states:
Important
If your app is linked on or after iOS 9.0, you must declare the URL schemes you pass to this method by adding the LSApplicationQueriesSchemes key to your app's Info.plist file. This method always returns false for undeclared schemes, whether or not an appropriate app is installed. To learn more about the key, see LSApplicationQueriesSchemes.
So you need to add the following keys to your info.plist, in case you are using the custom whatsapp scheme:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
</array>
till date: 27-06-2022
using package: https://pub.dev/packages/url_launcher
dependencies - url_launcher: ^6.1.2
TextButton(
onPressed: () {
_launchWhatsapp();
},
)
_launchWhatsapp() async {
var whatsapp = "+91XXXXXXXXXX";
var whatsappAndroid =Uri.parse("whatsapp://send?phone=$whatsapp&text=hello");
if (await canLaunchUrl(whatsappAndroid)) {
await launchUrl(whatsappAndroid);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("WhatsApp is not installed on the device"),
),
);
}
}
Here is new update way...
whatsapp() async{
var contact = "+880123232333";
var androidUrl = "whatsapp://send?phone=$contact&text=Hi, I need some help";
var iosUrl = "https://wa.me/$contact?text=${Uri.parse('Hi, I need some help')}";
try{
if(Platform.isIOS){
await launchUrl(Uri.parse(iosUrl));
}
else{
await launchUrl(Uri.parse(androidUrl));
}
} on Exception{
EasyLoading.showError('WhatsApp is not installed.');
}
}
and call whatsapp function in onpress or ontap function
For using the wa.me domain, make sure to use this format...
https://wa.me/123?text=Your Message here
This will send to the phone number 123. Otherwise, you will get an error message (see? https://wa.me/?text=YourMessageHere ). Or, if you don't want to include the phone number, try this...
https://api.whatsapp.com/send?text=Hello there!
Remember, wa.me requires a phone number, whereas api.whatsapp.com does not. Hope this helps!
I know it is too late for answering this, but for those who want the same functionality, the current way is to do it like this:
launchUrl(Uri.parse('https://wa.me/$countryCode$contactNo?text=Hi'),
mode: LaunchMode.externalApplication);
if you will use URL Launcher then the whatsapp link will be open on web browser. So you need to set parameter - not to open on safari browser. The complete code you can find on this flutter tutorial.
But for your case use below code.
await launch(whatappURL, forceSafariVC: false);
Today i am adding solution its working fine on my desktop and phone
Add 91 if your country code is +91
Remember not add any http or https prefix otherwise wont work.
whatsapp://send?phone=9112345678&text=Hello%20World!

Using audio files as no input prompts in Google Actions

I am trying to set up re-prompts in my Google Action, and I require them to be audio files.
This is my implementation:
'use strict';
const { dialogflow } = require("actions-on-google");
const functions = require("firebase-functions");
const app = dialogflow();
app.intent('Default Welcome Intent', (conv) => {
conv.noInputs = [`<speak> <audio src = "https://myurl.com/audio/myfile.mp3">My audio file</audio></speak>`];
console.log("Logging the conversation object... ");
console.log(JSON.stringify(conv));
conv.ask("Hello! ");
});
exports.yourAction = functions.https.onRequest(app);
However, at the moment it will just read the raw string of this noInputs array when I do a "no input" in the dev console!
Using this kind of static no-input handling is not suggested.
Better is to create an Intent that handles the actions_intent_NO_INPUT Event. You can then use the response section (or a response from your Fulfillment) to include SSML with the audio tag.

Express [413 too large] with QuillJS image

I am trying to use QuillJS to let the user write a rich text, and then store it as JSON to display later on. There are 2 of these rich text areas in a single form, and may include images. QuillJS encodes images as base64 strings, and my POST request results in 413 by Express.
I have tried to change the limits by adding express json parameters, even trying extreme numbers.
// app.js
//----------------------------------------------------
// Middlewares
//----------------------------------------------------
app.use(express.json({limit: '2000mb'}));
app.use(express.urlencoded({extended: true, limit:'2000mb'}));
Even this did not help and I think it is not logical to let these parameters with such values.
I tried with json and urlencoded enctypes. When I tried to post with multipart/form, req.body was empty.
// My html page (pugJS)
form(enctype='application/x-www-form-urlencoded', action='/editor/page',
method='POST', onsubmit='return addContent()')
.form-control
label Content-1
div#toolbar
div#editor
input#content(name='content', type='text', hidden)
addContent() function that runs before form submit simply changes input#content's value with JSON.stringify(#editor.getContents())
I want to be able to store two quill content in a single database row, to display later.
A better approach to this would be to overwrite the image upload function and then save the image in Amazon S3 or some cloud server. Then you paste it inside the editor as <img src="http://uploaded-image-url"> This would solve your problem of maximum memory issue.
I fixed my problem few hours before #argo mentioned and I did it that way. So I wanted to post little bit of detail to the solution. I have been also guided by a github issue but can't seem to find the link again, in case I find it I will edit the post and add it.
// Quill - EN content
var quillEn = new Quill('#editor-en', {
modules: {
toolbar: toolbarOptions
},
theme: 'snow'
});
// set custom image handler
quillEn.getModule('toolbar').addHandler('image', () => {
selectLocalImage(quillEn);
});
// create fake input to upload image to quill
function selectLocalImage(editor) {
const input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('accept', 'image/png, image/jpeg')
input.click();
// Listen upload local image and save to server
input.onchange = () => {
const file = input.files[0];
saveImageToServer(editor, file);
};
}
// upload image to server
function saveImageToServer(editor, file) {
const fd = new FormData();
fd.append('image', file);
const xhr = new XMLHttpRequest();
xhr.open('POST', '/api/page/upload_image', true);
xhr.onload = () => {
if (xhr.status === 200) {
// this is callback data: url
const url = JSON.parse(xhr.responseText).data;
insertToEditor(editor, url);
}
};
xhr.send(fd);
}
// manipulate quill to replace b64 image with uploaded image
function insertToEditor(editor, url) {
// push image url to rich editor.
const range = editor.getSelection();
editor.insertEmbed(range.index, 'image', url.toString());
}
In the backend where you POST image, you must return json as { data: FullUrlToImg } with 200 response, if you want to change your status to 201 or something else, don't forget to update it in saveImageToServer function.
So to summarize, you set custom image handler for your quill editor, you post the image to server as soon as user chooses to insert, then you replace the URL with your uploaded image in the editor.
Thanks.