How to know if an user is offline already by the time I send him/her a message? - nginx

I am building a chat based on Comet technology and I am stuck with this problem. So, for comet, i am using ningx with it's push module. Everything works fine. I can send messages to another user via dedicated channels. However, the problem appeared when I started thinking what will happen to the message which was sent to a user who went offline before receiving that message.
I'd like before pushing the message into a channel to check if the receiver is still listening that channel. If so, I will just push the message otherwise I want just put the message into the database so that the user could read it when he/she is online.
QUESTION:
Can I check somehow if a specific channel currently has at least one subscriber (for nginx push module)? if it's impossible then how to know for sure that the user to who the message is sent is online? (last activity is not going to help, cuz it's impossible to be sure that the user did not go offline one second before he/she was supposed to receive the message)
Thanks!

I've answered on my own question. Here's the code I use to publish a message and how I get an useful information back after publishing it.
$channel_id = 'c'.$_POST['uid'];
$message['sender']=$_SESSION['user.ID'];
$message['firstname']=$_SESSION['user.firstname'];
$message['message']=$_POST['msg'];
$message['type']='chat';
$c = curl_init('http://192.168.56.101/publish?cid='.$channel_id);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, 'pre('.json_encode($message).')');
$r = curl_exec($c);
in this example var $r contains this: queued messages: 0 last requested: 4 sec. ago (-1=never) active subscribers: 1
as u can see, it also contains a number of subscribers

Related

telegram use schedule message

I want to schedule a telegram bot message to be sent at a specific unixtime.
As from telegrams official api (https://core.telegram.org/api/scheduled-messages) that should be possible by setting the schedule_date flag.
To schedule a message, simply provide a future unixtime in the schedule_date flag of messages.sendMessage or messages.sendMedia.
However I was not able to set that flag. To be more precisely, I do not even know how to set a flag, or if I am using the correct api.
What I have tried is to use the api directly via the browser (could use curl as well) like so: https://api.telegram.org/botBOT:TOKEN/sendMessage?chat_id=ID&text=Test&schedule_date=1653503351
I also did not find any way to access this flag via https://pypi.org/project/pyTelegramBotAPI/#description https://telepot.readthedocs.io/en/latest/#send-a-message, nor https://github.com/nickoala/telepot.
I want to implement this feature in a python environment, but any working suggestion would be much appreciated.
EDIT:
I decided to save the intention to send a telegram bot message at a certain unixtime in a database. I then create an infinite loop that checks if there are any unsent messages before the current timestamp. If the loop detects such a message it sends the message and sets a flag, that that message has been sent.
And as promised, here is a fully dockerized example of that behaviour in action: https://github.com/Sokrates1989/nameTheCountDown-lightweight
It creates a bot that you can pass a name and the duration. Once the duration has passed it sends a message with the passed name. Basically a simple countdown that you can give several names, that run simltaniously. As it is a telegram chat, you can modify the way you are informed about the end of a countdown by modifying the notificaiton of that chat.
And here is the Bot in action: http://t.me/NameTheCountdownBot
We can't do this by bot API itself, and there's no schedule_date parameter in sendMessage method:
https://core.telegram.org/bots/api#sendmessage
And what you've read is for Telegram clients, not bot API consumers.
If you don't really need unixtime, you can simply create a table for scheduled messages with a text, chat_id and a publish_time column (like 22:15), and run a command every minute to look if there's a message for current time to send. Then send the message and delete the record.
Note that the python-telegram-bot library has a built-in solution for scheduling tasks: The JobQueue. This feature is based on the APScheduler library, which you can ofc also use without python-telegram-bot.
Disclaimer: I'm currently the maintainer of python-telegram-bot.
https://core.telegram.org/method/messages.sendScheduledMessages
Now you can send scheduled messages right away

Forwarding Every new messages of a public channel

I want to write a bot with a program that forwards every single new message of a public channel to me.
For example, channel "A" posts a new message (this message can be varied on its types), and then my bot should immediately forward this new message to me.
I really appreciate it if you can comment any code sample for this issue.
Pyrogram's Documentation has several examples. You can use the Echobot example and adapt it to watch for a specific chat and use the bound method .forward() instead.
https://docs.pyrogram.org/start/examples/echobot
On another note; Bots can only exist as Admin in a channel. You'd have to ask the admins of the channel to add your bot as an admin, or you'll have to use a userbot. The Code itself will be the same in both cases, with the exception of the added bot token in your code/config.

Queue of Future in dart

I want to implement a chat system.
I am stuck at the point where user sends multiple messgaes really fast. Although all the messages are reached to the server but in any order.
So I thought of implementing a queue where each message shall
First be placed in queue
Wait for its turn
Make the post request on its turn
Wait for around 5 secs for the response from server
If the response arrives within time frame and the status is OK, message sent else message sending failed.
In any case of point 5, the message shall be dequeued and next message shall be given chance.
Now, the major problem is, there could be multiple queues for each chat head or the user we are talking to. How will I implement this? I am really new to dart and flutter. Please help. Thanks!
It sounds like you are describing a Stream - a series of asynchronous events which are ordered.
https://www.dartlang.org/guides/language/language-tour#handling-streams
https://www.dartlang.org/guides/libraries/library-tour#stream
Create a StreamController, and add messages to it as they come in:
var controller = StreamController<String>();
// whenever you have a message
controller.add(message);
Listen on that stream and upload the messages:
await for(var messsage in controller.messages) {
await uploadMessage(message);
}

System Center Configuration manager Push Notification with read receipents

We need to push Push Pop up notifications for ex: “urgent message to warn users” and also generate a report on the success rate as to how many users in the network received it and read it, how many users did not receive it or did not read it.
Microsoft has suggested to use SCCM Power Schell scripting to send Client notifications with close button to confirm receive.
Is there any other way of accomplishing it through SCCM without any customization?
Have you considered pushing a VBScript to all clients which displays the message? If the user clicks "OK" to say they've read and understood the message then it could exit with a return code of 0, otherwise it could return a 1. It's then trivial to report each computer's success result in SCCM.

NopCommerce will not mark off messages as sent in message queue and keeps on flooding with E-mails

I have just installed nopcommerce 1.9 and now configuring it.
Inputed all the correct settings for the SMTP (Host, port etc.) and the test E-mail arrives fine to any address I tested it with.
However should I fill in the contact form or have a new user sign-up the store can't stop sending the same message over and over again to the default store E-mail address or to that of the user. Keeps sending the welcome to the store E-mail for those that signed up or the message body of the contact form etc. To stop it I have to go to message queues and delete the message(s) from there manually, these messages are are flagged as unsent! Even though they have been sent out many times obviously.
So it re-sends everything being sent by the store non stop even though the message went out fine the first time.
Anyone know why it's doing this? Have confirmed I have correct settings for the smtp with my webhost provider, nothing in mail error log of worth.
Thanks...
If you run nopCommerce 1.90 under medium trust, please follow the next steps in order fix the issue when customers keep receiving mails:
Open \Libraries\Nop.BusinessLogic\Messages\MessageService.cs file
Find UpdateQueuedEmail method
Replace
if (!_context.IsAttached(queuedEmail))
_context.QueuedEmails.Attach(queuedEmail);
with
if (!_context.IsAttached(queuedEmail))
_context.QueuedEmails.Attach(queuedEmail);
_context.ObjectStateManager.ChangeObjectState(queuedEmail, System.Data.EntityState.Modified);
Recompile the solution
...or simply redownload the latest version here (the version is still 1.90)

Resources