I need to do local notification with an end date. I have taken look at https://wix.github.io/react-native-notifications/docs/localNotifications/ and https://github.com/zo0r/react-native-push-notification but cannot find an example of how it would work. I want a notification to have start and end date with an interval
This is answer is geared towards the second library you mentioned: https://github.com/zo0r/react-native-push-notification.
For setting the start date for when a notification should occur we have
the localNotificationSchedule method described in the documentation here: https://github.com/zo0r/react-native-push-notification#scheduled-notifications.
For example:
import PushNotification from 'react-native-push-notification';
PushNotification.localNotificationSchedule({
id: "1",
message: "My Notification Message", // (required)
date: new Date(Date.now() + 60 * 1000), // in 60 secs
// other props...
});
So whatever date object you pass to the date property will be the moment the notification is triggered.
Note that autoCancel by default has the value of true so after the notification is delivered the notification will be canceled anyway. So it's better not to handle the end date as it's already handled for you.
If you still want to cancel it anyway you can add autoCancel: true to the example above and cancel the notification like this:
PushNotification.cancelLocalNotifications({id: '1'});
So if you want to control the end date, an idea could be to first trigger your push notification and directly after call cancelLocalNotifications inside setTimeout. Then you could control when the notifications starts and when it is canceled.
If you want to have a way to do this in the background you can look into a background task library like https://github.com/transistorsoft/react-native-background-fetch.
Related
I am trying to make an app that utilizes expo's local notification feature and have run into an issue. I would like to make a notification that repeats every day at a certain interval with its data changing each day. I tried to use this syntax below, but it did not work as it only ran the function once, setting that value in stone for the rest of the notifications to come.
Expected (10 mins: "1", 20 mins: "2", 30 mins: "3" etc.)
Actual (10 mins: "1", 20 mins: "1", 30 mins: "1" etc.)
Notifications.scheduleNotificationAsync({
content: {
title: 'My Notification',
body: this.someFunctionThatReturnsANewValue()
},
trigger: {
minutes: 10,
repeats: true
}
});
In that case, I wanted to know if anyone had any idea on how to make a notification that uses the repeat property and has a body component that changes values each time it is triggered. The only other way I can think of giving a notification a different value as the last is scheduling 100+ notifications in advance, but that is not pretty nor practical. Any help or suggestions towards how I can accomplish this would be greatly appreciated, thanks!
In your component's useEffect or your application's App.js declare the Notifications.addNotificationReceivedListener event. It will be executed every time the application receives a new notification. Within the asynchronous function execute "await Notifications.cancelAllScheduledNotificationsAsync ();" to clear the scheduled notification and call Notifications.scheduleNotificationAsync again with the new message. The use of
repeats: true in this case is not necessary. Doing this, every time the application receives a notification it clears the one that existed before and programs a new one with a different message
I have researched high and low through multiple websites and have not found a single fully documented solution for round-robin call forwarding with-in the Twilio stack; let alone within Twilio Studio. The last time this question was asked in detail was in 2013 so your help is greatly appreciated. I am looking to find a solution to the following to educate myself and others:
[Round Robin Scenario]
Mentioned by Phil Krnjeu on Aug 1 '13 at 23:04, "I'm trying to create a website that has a phone number on it (say, a phone number for a school). When you call that number, it has different secretary offices (A,B,C, D). I want to create something where the main number is called, and then it goes and calls phone number A the first time, the second time someone calls the main number, number B is called, C, then D. Once D is called (which would be the 4th call), the 5th call goes back to A."
The response to the above question was to use an IVR Screening & Recording application which requires the caller to pick an agent which is not a true Round Robin solution. The solution I am looking for and many others require the system to know which agent is in a group and which agent is next to receive a call.
[Key Features Needed]
Ability to add forwarding numbers as identified above A, B, C, D as a group or IVR extensions such as 1 = Management, 2 = Sales and etc...
Set a subsequent calling rule that notates in a DB of some sort. Caller A through D, for example, equals 1 unsuccessful. When caller A has been forwarded a call it now equals 0 successful then the script stops and allows the call to be answered by the user or its voicemail. Then the next call comes in and is forwarded to user B and assigned a 0 successful value, then the script stops.
After the caller finishes the call or finishes leaving a voicemail the script needs to end the call.
[Final Destination]
The round-robin should finalize its call with the forwarded phone numbers voicemail.
[Known Issues]
Forwarding a call to multiple numbers not stopping when someone answers
[Options]
Once this question is posted I am sure someone will ask in the near future what if I wanted the call to be forwarded to a Twilio voicemail instead of using the forwarded phone number's voicemail which could be let's say a cell phone. I do not necessarily need this feature, however, making an additional comment would be very helpful to the community. Thank you for your time.
I have limited knowledge of programming besides having the ability to review articles posted by other users. One article I researched in detail that did not work for me was, "IVR: Screening & Recording with PHP and Laravel."
The solution I am looking for first would be to make this code through the new Twilio Studio interface if that is not possible then any other solution would be helpful to all.
Sam here from the Twilio Support Team. You can build what you've described using Twilio's Runtime suite, Studio, and Functions.
I wrote a blog post with detailed instructions and screenshots here, and I've included a summarized version below as well.
CREATE YOUR VARIABLE
First, you need to create a serverless Variable which will be used as the round robin counter. The variable must be inside an Environment, which is inside a Service. This is the only part of the application where you will need your own laptop. You can see how to create these with any of the SDKs or using curl in the docs.
Create a Service
Create an Environment
Create a Variable
Be sure to copy the SIDs of your Service, Environment, and Variable since you will need that for your function.
For convenience, this is how you create the Variable in NodeJS.
const accountSid = 'your_account_sid';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);
client.serverless.services('ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
.environments('ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
.variables
.create({key: 'key', value: 'value'})
.then(variable => console.log(variable.sid));
CREATE YOUR FUNCTION
Create the following Environment Variables here in the console and save set them equal to their respective SID that you saved earlier.
RR_SERVICE_SID
RR_ENV_SID
RR_VAR_SID_CTR
Next, make sure you check the Enable ACCOUNT_SID and AUTH_TOKEN checkbox above the Environment Variables section under Credentials.
Be sure your Twilio Client version in the Dependencies section is set to the latest, so we can be sure it includes the Serverless resources. At the time of writing (March 2020), the default Client version does not include them, so we upgraded to 3.41.1, which was the latest.
Go here in the console and create a blank Function.
Copy and paste the following code and replace the numbers with the ones you would like to include in your Round Robin (make sure the environment variables you just created match what's in the code).
exports.handler = function(context, event, callback) {
// Number List
let numbers = [
"+18652142345", //Sam
"+18651092837", //Tina
"+19193271892", //Matt
// Copy and paste line above to add another number.
];
// Initialize Twilio Client
let client = context.getTwilioClient();
// Fetch Round Robin Ctr
client.serverless.services(context.RR_SERVICE_SID)
.environments(context.RR_ENV_SID)
.variables(context.RR_VAR_SID_CTR)
.fetch()
.then(variable => {
// Use counter value to determine number to call
let number = numbers[variable.value];
// Create var with new ctr value
let ctr = variable.value;
// Check if current counter value is less than RR length (i.e. the number of numbers in round robin)
// If so, increment
if(ctr == numbers.length-1) {
ctr = 0;
}
// Otherwise reset ctr
else ctr++;
// Update counter value
client.serverless.services(context.RR_SERVICE_SID)
.environments(context.RR_ENV_SID)
.variables(context.RR_VAR_SID_CTR)
.update({value: ctr})
.then(resp => {
// Return number to call
let response = {number};
// Return our counter value and a null error value
callback(null, response);
});
});
};
CREATE YOUR STUDIO FLOW
Click the red plus sign to create a new Flow here.
Give the Flow a name and click Next.
Scroll to the bottom of the templates and click 'Import from JSON' and click Next.
Paste the Flow JSON shown here and click Next.
Click the RoundRobin function widget and select the Function you just created under the Default service.
Click the FunctionError widget, click MESSAGING & CHAT CONFIG, and change the SEND MESSAGE TO number to a number that you would like to notify by text in the event of a Function failure.
Click the DefaultNumber widget and change the default number that will be forwarded to in the event of a Function failure.
Click the Publish button at the top of your Flow.
CONFIGURE YOUR TWILIO NUMBER
Go here in the console.
Click the Twilio number you would like to configure.
Scroll down to the A CALL COMES IN dropdown in the Voice section and select Studio Flow.
Select your new Flow in the Select a Flow dropdown to the right.
Click Save at the bottom.
And that's it. You're now all set to test!
My email will occasionally get queued instead of sending download link immediately using a paid Mandrill account- other times it will send quickly. I would like it to be send at time of calling the API. The are no errors in the Mandrill API control panel.
This code works great most of the time via a node server on Heroku...I am using 'send_at' parameter w current Date using the javascript Date() method. How can I send an email consistently - sometimes queues can be 1 hour 30 min long.
// Text version of message
me_data.text += message;
// Html for message
me_data.html = results['html'];
// current Date for sending
var sendDate = new Date();
mandrill_client.messages.send(
{"message": me_data, "async": async, "ip_pool": ip_pool, "send_at": sendDate},
function (result) {
console.log(result);
//success
},
function (e) {
//_____________________________Error
console.log('A mandrill error occurred: ' + e.name + ' - ' + e.message);
}
);
This issue is no longer a problem. Please ignore the above posts about the time parameter as I am using this variable (clearly "send_at" from API doc) and Mandrill is sending.
This must have been a fluke of timing as I had paid a short time before launching production app. You have to pay (set credits) in Mandrill to use the send_at parameter - in other words upgrade from the free version. It may take some time to come into effect.
Mandrill has been working flawlessly since this issue like quick as lighting. So this is not an issue any longer for my stuff.
I'm using the Distriqt PushNotifications ANE and PARSE to send PushNotifications, and so far everything is working PERFECTLY.
This means, I register my iOS devices and receive PushNotifications as it should be....
When I send PushNotifications with PARSE I use the badge:"Increment" value, which understandably increments the Value By +1.
After I open the App, I want to reset the BADGE to be at 0 and I use the setBadgeNumber(0) method... This also works, I tried with other values like 11, or 1 and it displays it correctly.
The Problem is that when I send another PARSE notification it displays now the old value + 1 !!!
Like so:
I use PARSE to send 3 PushNotifications
The badge displays (3)
I use the setBadgeNumber(0)
The badge displays (0)
I use PARSE to send 2 additional PushNotifications
The badge displays (5)!!!!
How can I really reset the badge?
The value of the badge is actually sent as part of the push notification payload, eg:
{
"aps" : {
"alert" : "Notification content",
"badge" : 5
}
}
You should double check what Parse is actually sending as it will be keeping a count of the notifications and sending that as part of the payload, so you will either need to disable this in Parse or notify Parse of your user resetting / changing the count.
Calling setBadgeNumber just changes the icon on the application and doesn't update Parse of this change.
You could look into the Parse ANE which helps out with this process:
http://airnativeextensions.com/extension/com.distriqt.Parse
I am working in sencha touch and now I want to use the local notification in my project so I used this plugin for the local notification.
https://github.com/katzer/cordova-plugin-local-notifications
the problem that I face is just that I can't display my notification on a specific time and date. It shows immediately the notification as i clicked on the action button so please help me out from this problem.
The example below should work. I tested it myself. Be aware that if the date is in the past according to your phone the notification will pop up directly after you have set the notification.
var beginTime = new Date('2016', '0', '12', '12', '45');
//year
//month - 1 (month starts at 0 so you have 0-11)
//day
//hour
//minutes
cordova.plugins.notification.local.schedule({
id: 1,
title: 'Hello World',
text: 'My first notification',
at: beginTime
})