Trigger for a Pro active reminder bot - c#

Hi I am making a reminder feature for a bot framework chat bot using c#.
What is the best trigger for a proactive reminder? I saw samples using task delay. is it applicable for reminder that can be set to 30 days from now or every 15 days? if I use a post API to send a proactive reminder. Is there a third party app that can trigger the post request with data coming from a database automatically?

You probably don't want to use Task.Delay for the order of days - if you program dies during that time the reminder will be lost.
Usually you would store a DateTime for when the reminder should fire, then have a job that polls every so often and if the current DateTime is after that one, then it fires. This way it will survive reboots/changing instances etc. and as a bonus makes it easier to test your logic and change the reminder date and time after it is saved.

Related

Global timer for all users

How would you go about creating a global timer all users use? Such as a tournament and every 24 hours the timer resets. How would you make all users see the same time and not base it off the client side?
I'd think to use a service like playfab or app42, but how would this work through them anyway?
Thanks
Since there is no code here im gonna tell you the how to but you will need to do research in order to achieve it probably.
You can have a time span in your server, and every time a user logs in you send the time span since the server started to run minus the time that the server has been running, and the client starts running its own timer taking into account that time span.
Im assuming you are working with a client server model here.

C# webapp internal notification system design

I'm new to web application design and I appreciate if you can share you experience and knowledge on the following question.
Usecase / background:
I'm building a web app that keeps track of our customer interactions. When a customer starts interact with my webapp, I have to make an API call saying interaction is ACTIVE. When this customer stops the interaction​, I'm setting the customer state to IDLE with a time limit of 30 minutes. After the 30 minutes of inactivity, I have to make another API call saying interaction is ENDED.
My current approach:
I'm saving the IDLE customers' user IDs to a database (redis). I also have a scheduled event that fires every minute which queries my IDLE id database. When I find the expired ids (pass 30 mins), I delete those ids and make the final API call (ENDED).
Question:
Is there a better way to implement this considering scalability and reliability? Ideally, I'd like a notification system where I can make an API call to register to a notification with a customer id, a time limit, and a callback URL. When the time limit expires given callback URL endpoint should be notified. Is there a industry accepted solution for like this? If yes, is it really better than my current approach? How would you implement the very system?
Any feedback anf design tips will be greatly appreciated.
Thank you for your time.

Scheduler to do some tasks on time

I am working on a scheduler to do certain tasks like send email to users etc. Its a basic one which runs every 5 mins and do its job. I need to make some modifications into that so that it can work on demand. For example, I need to send email to a user at 11:00 AM, to another user at 11:02 AM. How can I make the scheduler to run on time without using a lot of resources on server. I know if I need to send emails every minute, then its sleep time should be one minute or less.
Is there any way to call it on demand or I need to have one thread active all the time to check when to do what and at that time activate scheduler or other process responsible for sending email.
Please suggest. Your inputs will be valuable.
Thanks.
If you need to send emails every minute it would be better to create a service and have the service poll the database every minute to look for work and sleep for 1 minute in between loops.
If you only need to run your code once an hour it would be better to use the Windows Task Scheduler.

Invoke popup as reminder in asp.net MVC

I have a functionality where I need to remind the customers about their appointments before the time interval set while creating the appointment.
Example:
A customer is logged into the system today at 4:00PM.
If a customer has an appointment set today at 5:00PM , and the reminder minutes as 10.
This invokes a popup with beepsound that has to appear today at 4:50PM(i.e 10 minutes before the actual appointment start time).
I have all appointments with start time, end time , (along with the dates) stored in backend table for number of customers.
Please guide me to achive the following in realtime :
(1) to invoke this popup at 4.50PM
(2) play the soundfile stored in the database
From my search,there is a way to do this using signalr concept in mvc. I went through the sample for chat application in this lnk.
http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr
This invokes the hub when a event occurs. but in my application it has to work as a reminder to show the popup if the start time matched the current time. how to get this in real time. Any idea can help me.
This could be a good situation to use WebSockets. (Take a look at Socket.IO, and it's .NET version SocketIO4Net)
The idea would be to have a business logic server side to manage what customer has an appointment to be reminded. Then it uses the WebSocket to send the reminder signal. If the customer is logged in, the js client side would catch the signal and you decide how you want to show it.
To play the sound stored in the database, you could do an action server side that returns the sound file or something, and then use an HTML 5 tag to play the sound.
Hope this helps.
Everything can be done but as ChristianDev says SignalR does not work like this out of the box... I think you can do this with SignalR anyway but you have a few challenges...
You have to maintain state on the server for the clients appointment
This state have to be persistent between connection, when a client navigates between pages
When an event fires you have to send the message to the correct client
If that client is between pages (offline) at the moment that message have to be stored until the client gets back online and then be sent to him/her.
EDIT: It seemed like a fun thing to write so a wrote a simple notification application. You can probably port it to SignalR pretty easy. Realtime Notification Sample
You could change the approach, and use a windows service, emailing/sms'ing the user to remind them of the appointment, this means that the user doesn't need to be logged into the web application to receive a reminder.
If you wanted to use technology such as SignalR, you would need to keep a record of connected users (and their username) and then when an appointment is due, you would need to trigger an event to send to the user in question, based on the unique connectionId.
SignalR, out of the box, doesn't work like this - but, take a look at my question here for some help : Update UI with SignalR and Knockout when manually updating DB
Edit: To add to this, if you're looking for a very nice notification plugin, then take a look at John Papa's ToastR, it's a small JS/Css plugin which notifies via a 'timed, outlook style notification'.

Schedule method invocation C#

I'm using c# to communicate with twitter and i need to code a schedule system to send twitter messages at a user defined date.
The messages to be sent are in a database with the date and time of deliver.
Which is the best method to check the db for scheduled messages and send it when the time arrives?
How accurate do you need the timing to be? Could you get away with polling the database every 5 minutes, saying "Tell me all the messages which need to be delivered before current time + 5 minutes" and then sending them all? (And marking them as sent in the database, of course.) Does it matter if they're a bit early or late?
You can do the scheduling on the C# side to make it more accurate, but unless you really need to I'd stick with a very simple solution.
(Depending on your database there may be clever ways of getting callbacks triggered etc... but again, I'd stick with the simplest solution which works.)
In addition to the windows service option (or background thread), you could just set up a scheduled task to run an app that polls the DB and sends the tweets once every defined interval.
Windows schedules can be setup using C# if needed and are really easy to set up manually.
There are several ways to do this, but I guess the best way is to set up a Windows Service that will periodically poll (frequency is up to you) the DB for any scheduled tweets that hasn't been sent.
Needless to say you'll need to handle scenarios such as the Internet connection or DB being down, etc.
In fact the solution consists in using a windows service but it can't communicate directly with the ASP.NET MVC app. I've added a Web Service that handles the task and a System.Threading.Timer in Windows Service to periodically call the Web Service.

Categories

Resources