How to read number and body sms when event incoming sms in phonegap? - phonegap-plugins

I ever made a sms filter in android, now i wanna use phonegap. what
API can i use to read the number and content of the sms with
PhoneGap when incoming sms?

Below is a link to a phonegap plugin that allows you to receive incoming SMS. You have the possibility to stop the message broadcasting and, thus, avoid the incoming message native popup.
All you have to do is follow the following steps to setup your SMS Receiver.
Adding the plugin to your project
(Make sure you are using Phonegap > 2.0)
1 .Move SmsInboxPlugin.js to your project's www folder and include a reference to it in your html files.
2. Add the java files from src to your project's src hierarchy
3. Reference the plugin in your res/config.xml file
4. Ensure that your manifest contains the necessary permissions to send SMS messages:
Include the following script in your html file.
var smsInboxPlugin = cordova.require('cordova/plugin/smsinboxplugin');
smsInboxPlugin.isSupported ((function(supported) {
if(supported)
alert("SMS supported !");
else
alert("SMS not supported");
}), function() {
alert("Error while checking the SMS support");
});
smsInboxPlugin.startReception (function(msg) {
alert(msg);
}, function() {
alert("Error while receiving messages");
});
To stop reception use this script
smsInboxPlugin.stopReception (function() {
alert("Correctly stopped");
}, function() {
alert("Error while stopping the SMS receiver");
});
The plugin can be found at https://github.com/Pyo25/Phonegap-SMS-reception-plugin

Related

Playing custom notification sound using Cloud Functions - iOS

I'm sending notification to my client app using Cloud Functions and GoogleCloudMessaging in this way:
const notificationContent = {
notification: {
title: `${senderName} has sent you a message`,
body: `${messageString}`,
icon: "default",
sound: "customNotificationSound",
},
};
return admin.messaging()
.sendToDevice(notifToken, notificationContent)
.then((result) =>{
console.log("write done correctly");
});
I want to use a custom notification sound instead of the default one; so I followed some guides online like this, this and this but they don't seem to answer my question.
Since I'm sending the push notification from the cloud function, do I still need to load the sound file in the client Main Bundle (I tried it and in fact it doesn't seem to work).
Or do I have to upload it somewhere else?
P.s. also the sound file extension is .wav so there shouldn't be problems for that matter.
I solved this and the answer is Yes, you still need to upload the music file in your main bundle even tough you're sending the push notification from cloud functions

How to integrate React native navigation with AWS Amplify push notifications in android?

I am trying to get FCM push notifications working in my react native project for android with react-native-notification library and aws-amplify. I have an issue with PushNotification.onRegister method is not called in android to get device token to send remote notifications.How can I make these two library working together in my react native project?
I followed aws-amplify documentation https://aws-amplify.github.io/docs/js/start?ref=amplify-rn-btn&platform=react-native
to include amplify library in react native project.
I then added push notifications set up as per https://aws-amplify.github.io/docs/js/push-notifications
I have included react-native-navigation library to support navigation in my react-native app as per
https://wix.github.io/react-native-navigation/#/docs/Installing
After the installation react-native navigation library pushNotification.onRegister method is not getting called to receive device token without which I am unable to send push notifications in android.
I have push notifications configured in App.js as per below
import PushNotification from '#aws-amplify/pushnotification';
import Analytics from '#aws-amplify/analytics';
import Auth from '#aws-amplify/auth';
// retrieve temporary AWS credentials and sign requests
Auth.configure(awsconfig);
// send analytics events to Amazon Pinpoint
Analytics.configure(awsconfig);
console.log(PushNotification);
PushNotification.configure(awsconfig);
Then in the constructor of App.js I am registering for PushNotification events.
Navigation.events().registerAppLaunchedListener(() => {
PushNotification.onNotification((notification) => {
// Note that the notification object structure is different from Android and IOS
console.log('in app notification', notification);
// required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
notification.finish(PushNotificationIOS.FetchResult.NoData);
});
// get the registration token
PushNotification.onRegister((token) => {
Alert.alert(token);
this.setState({token:token});
console.log('in app registration', token);
});
// get the notification data when notification is opened
PushNotification.onNotificationOpened((notification) => {
console.log('the notification is opened', notification);
});
});
This set up works fine and PushNotification.onRegister event is called and device token is getting printed if I don't include react-native-navigation library.
In iOS I am able to get device token with react-native-navigation library but in android it is not working. Any pointers on this issue would be greatly appreciated!
See here: https://github.com/aws-amplify/amplify-js/issues/2541#issuecomment-455245033
the Android app calls .onRegister() once only, when the app/device is completely new. The calls afterwards seems to load from cache.

How to catch Facebook messaging_optins with Azure Bot Channels Registration + Botbuilder SDK?

I've got a chatbot up and running, built using Node.JS Microsoft Bot Framework, and deployed to an Azure server as a Web App, with a Bot Channels Registration resource as the frontend endpoint.
This Bot Channels Registration is connected to Facebook Messenger (via a FB App) - meaning, the webhook for the Facebook App points to https://facebook.botframework.com/api/v1/bots/<BOT_CHANNELS_REGISTRATION_RESOURCE_NAME>.
This all works well for normal chat functionality.
However, I'd now like to add an opt-in checkbox to a separate web page I have. This checkbox works by pinging FB, which then sends a very specific payload to the already configured bot webhook.
{
"recipient":{
"id":"<PAGE_ID>"
},
"timestamp":<UNIX_TIMESTAMP>,
"optin":{
"ref":"<PASS_THROUGH_PARAM>",
"user_ref":"<UNIQUE_REF_PARAM>"
}
}
My question is this:
How does the Bot Channels Registration receive and handle the above payload? Will it just automatically forward it to the Messaging Endpoint I have configured in the Bot Channels Registration settings? Or will it get stuck, and never reach my actual bot Web App?
Finally, if it does reach my normal messages endpoint, how can I handle the specific payload with my botbuilder.ChatConnector() listener? Given that my web app code looks like (in essence)
var restify = require('restify');
var builder = require('botbuilder');
var dialogues = require('./dialogues');
var chatbot = function (config) {
var bot = {};
chatbot.listen = function () {
var stateStorage = new builder.MemoryBotStorage();
var connector = new builder.ChatConnector({
appId: process.env.APP_ID,
appPassword: process.env.APP_PASSWORD
});
bot = new builder.UniversalBot(connector, function (session) {
session.beginDialog(dialogues.base(bot).name);
}).set('storage', stateStorage);
return connector.listen();
};
return chatbot;
}
var server = restify.createServer();
// Listen for messages from users
server.post('/api/messages', chatbot.listen());
server.listen(process.env.port, function () {
console.log('%s listening to %s', server.name, server.url);
});
Thanks!
EDIT: I've figured out how to handle the above payload within my messaging endpoint - by adding a server.pre() handler to my server, e.g.
server.pre(function (req, res, next) {
if (req.body && req.body.optin_payload_specific_field){
// handle opt-in payload
} else {
return next();
}
});
However, via extra logging lines, it seems the opt-in payload isn't even making it to this endpoint. It seems to be stopped within the Bot Channels Registration. Currently looking for a way to resolve that major roadblock.
So, per #JJ_Wailes investigation, it seems like this is not a supported feature (in fact, it's a current feature request). See his comments on the original post for more details.
However, I did find a half-workaround to capture the user_ref identifier generated by the checkbox_plugin, for those interested:
1) From your external site, follow the steps from the documentation here for sending the initial user_ref to FB. FB will then make a callout to your bot, but per the above, that gets blocked by the Bot Channels Registration piece, so it's ignored.
2) From that same external site, use the user_ref to send a message to the user (just using the normal requests library). A successful send means that the user_ref was properly registered in FB by that step #1 call - a failure means you'll need to repeat step #1 (or use some other error handling flow).
3) After that, the next time the user responds to your bot in FB (as long as you don't send any other messages to them), the message your bot will receive will contain this as part of the payload:
{ ...
channelData:
{ ...
prior_message:
{ source: 'checkbox_plugin',
identifier: <user_ref> }
}
}
So I've currently added a check within my bot.use(), where if that section is present in the incoming message payload (session.message.sourceEvent.prior_message) and the source is "checkbox_plugin", I store the corresponding user_ref in the session.userData, and can work from there.
I would love to see this feature added into the supported Azure bot stack, but in the meantime hopefully this helps anyone else encountering this (admittedly niche) hurdle.

Receive GCM push notification in node.js app

I'm building a command-line application in node.js and would like to receive GCM push notifications (the command-line app will be interacting with the same set of services that iOS/Android apps use, hence wanted to use the same notification service).
Given that GCM can be used on iOS (and thus is not Android-specific) I am hoping it can be used from node.js as well.
I've seen many articles about sending push notifications from node.js, but haven't been able to find anything about using node.js on the receiving end.
i think if you have to send push notification ,to ios and andriod then fcm is better then gcm use this
router.post('/pushmessage', function (req, res) {
var serverKey = '';//put server key here
var fcm = new FCM(serverKey);
var token = "";// put token here which user you have to send push notification
var message = {
to: token,
collapse_key: 'your_collapse_key',
notification: {title: 'hello', body: 'test'},
data: {my_key: 'my value', contents: "abcv/"}
};
fcm.send(message, function (err, response) {
if (err) {
res.json({status: 0, message: err});
} else {
res.json({status: 1, message: response});
}
});
});
I believe you can using service workers.
Push is based on service workers because service workers operate in the background. This means the only time code is run for a push notification (in other words, the only time the battery is used) is when the user interacts with a notification by clicking it or closing it. If you're not familiar with them, check out the service worker introduction. We will use service worker code in later sections when we show you how to implement pushes and notifications.
So basically there is a background service that waits for push and thats what you are going to build.
Two technologies
Push and notification use different, but complementary, APIs: push is invoked when a server supplies information to a service worker; a notification is the action of a service worker or web page script showing information to a user.
self.addEventListener('push', function(event) {
const promiseChain = getData(event.data)
.then(data => {
return self.registration.getNotifications({tag: data.tag});
})
.then(notifications => {
//Do something with the notifications.
});
event.waitUntil(promiseChain);
});
https://developers.google.com/web/fundamentals/engage-and-retain/push-notifications/handling-messages
I don't think it possible (in a simple way)...
Android/iOS has an OS behind with a service that communicates with GCM...
If you are trying to run a CLI tool, you'll need to implement a service on top of the OS (Linux, Windows Mac) so it can receive notifications.
GCM sends the notifications against the device tokens which are generated from iOS/Android devices when they are registered with push notification servers. If you are thinking of receiving the notifications without devices tokens it is fundamentally incorrect.
It's not mandatory to depend only on GCM, today there are many packages are available for sending pushNotification.
Two node packages are listed below.
fcm-call - you can find documentation from https://www.npmjs.com/package/fcm-call
fcm-node
fcm-call is used - you can find documentation from https://www.npmjs.com/package/fcm-node/
let FCM = require('fcm-call');
const serverKey = '<Your Server Key>';
const referenceKey = '<Your reference key>'; //Device Key
let title = '<Your notification title here.>';
let message = '<Your message here>';
FCM.FCM(serverKey, referenceKey, title, message);
And Your notification will be sent within 2-3 seconds.
Happy Notification.

emitting a nodejs event when an event on google calendar is added or updated

Is this possible to emit a nodejs event when a Google calendar event is added or modified? On my nodejs server, I can get/list all the events on the calendar. But I would like to retrieve the events based on the nodejs event rather than checking it manually after a regular interval. Appreciate any ideas!
Actually, it is possible, as stated here: https://developers.google.com/google-apps/calendar/v3/push
You can register a callback URL so you app receives information when your event changes or gets modified. With the Node.JS API it's something like:
calendar.events.watch({
auth:jwtClient,
resource: {
id: "yourChannelId",
type: 'web_hook',
address: "https://www.yoursite.com/notifications"
},
calendarId: "yourcalendarId"
}, function(error, response) {
if (error) {
console.log(error);
return;
}
console.log(response);
});
Not possible. Something like that would require Google to know about your app (to send events or push data to). Google's APIs is only for meant to be accessed. It cannot "tell" your app anything. Your app has to be the one that "asks" Google whether or not something it wants exists or has happened.

Resources