I was wondering if I could send a message with my bot on telegram bot api, to multiple chat_id, but I cant figure it out. that's totally because of telegram apis are so hard to understand.
I have used this for send a message to one chat_id:
https://api.telegram.org/botTOKKEN/sendMessage?chat_id=xxxxxxx&text=Hi+John
There is no way to make bot to sendMessage to multiple chat id but there is a trick that can fix it for now :)
Why not sending each chat id a message ?!
Let's look at this example in PHP :
<?php
$message = "Hi John";
$chatIds = array("xxx","xxx","xxx"); // AND SOME MORE
foreach($chatIds as $chatId) {
// Send Message To chat id
file_get_contents("https://api.telegram.org/botTOKKEN/sendMessage?chat_id=$chatId&text=".$message);
}
?>
In addition to #farsad 's answer: Add sleep(NUMBER_OF_SECONDS); inside the foreach loop to not get banned by telegram. As there is a limit of 30 messages per second for bots in Telegram API
The problem with foreach or any other massive sendMessage is that the API will not allow more than ~30 messages to different users per second.
According to Bots FAQ in telegram site:
How can I message all of my bot's subscribers at once?
Unfortunately, at this moment we don't have methods for sending bulk messages, e.g. notifications. We may add something along these lines in the future.
In order to avoid hitting our limits when sending out mass notifications, consider spreading them over longer intervals, e.g. 8-12 hours. The API will not allow more than ~30 messages to different users per second, if you go over that, you'll start getting 429 errors.
You can't send message this way to all user.
and solution in Bots FAQ page:
My bot is hitting limits, how do I avoid this?
When sending messages inside a particular chat, avoid sending more than one message per second. We may allow short bursts that go over this limit, but eventually you'll begin receiving 429 errors.
If you're sending bulk notifications to multiple users, the API will not allow more than 30 messages per second or so. Consider spreading out notifications over large intervals of 8—12 hours for best results.
Also note that your bot will not be able to send more than 20 messages per minute to the same group.
Just for your information.
We could input the chat_ids to database. Query and loop the message section for sending the message to multiple chat-id with sleep().
I am not a programmer. So I could not make an example.
Related
I would like to send a notification to all the users in a system. I'm using Laravel framework. I believe there is a limit to the number of tokens a notification could be sent to.
Could you please help me find a solution to send the notification to users which might exceed 10,000? And what is the threshold of tokens that can be sent at a time?
Check this to answer your question on threshold limits.
If you dont want to manage your own infra for sending notifications, check https://ravenapp.dev . It provides a simple API to send any kind of and volume of notifications without writing any code.
I'm creating an app which will allow all users to initiate conversation with page owner using Chat-to-SMS service.
Problem is that I'm not sure how to track conversations since there would be one conversation chain from SMS Provider <-> page owner. When owner clicks reply, it needs to know which session user it needs to send the message to.
Basically, I need to do opposite what is being explained here: https://www.twilio.com/docs/quickstart/php/sms/tracking-conversations
How should I accomplish this? I can't quite wrap my head around this.
Twilio developer evangelist here.
If you are sending all the chat messages to just one SMS number then there is no easy way to tie replies back to the original message. (As a quick experiment, if you open an SMS conversation in your own phone and try to reply to any message that wasn't the latest one, you'll see it's not possible.)
There are workarounds though.
You could, when forwarding the message, generate an ID for it. Then get your page owner to include that ID when responding to that message, that way you can route the message back to the original sender and strip out the ID.
Alternatively, when replying you could always respond to the last message that came in. This relies on there not being much traffic, allowing the page owner to respond before the next message arrives. This is error prone though.
Another alternative is purchasing a new number for each new conversation. You could expire the number after a predetermined amount of time. This is made much easier with Twilio Proxy, which was announced recently and is currently in preview.
Let me know if that helps at all.
I need to send individual emails to 1500+ subscribers from a WordPress template page. They are not WordPress users but their details are stored in a non WordPress table.
Upon post update, I need to fetch their email addresses from the table and send individual emails to them. The email contains a unique link to unsubscribe.
I have everything working. The only thing is that when the post is updated, it keeps loading and loading as it is sending emails and eventually times out.
Can anyone please advise if there is a better solution to update the post but schedule emails or send emails in chunks of 50s?
As already mentioned in the comments there are some possibilities you can go with - letting WordPress send all those emails on save_post is certainly not a good Idea.
Here are three possible ways you can solve it:
1) Instead of wp_mail() you may want to implement a PHP library for sending many emails fast at once for instance PHPMailer (https://github.com/PHPMailer/PHPMailer).
Advantage: You do not need an external service and no cronjob.
Disadvantage: If the number of subscribers is growing to high this will fail, too.
2) Use an internal cronjob for WP and send chuncks of 50. There are many tutorials out there how WordPress Cronjobs work (https://codex.wordpress.org/Function_Reference/wp_cron)
Advantages: No external service required and almost no limitation in the number of subscribers.
Disadvantages: It will take some time until the WordPress cronjob has finished. It will slow down your site especially if you have many updates.
3) Use an external service like Mailchimp. Just have a look into their API and trigger the email sending.
Advantages: Many additional options. You do not have to implement any sending logic.
Disadvantages: Eventually costs money. Requires Integration of their API. You have to keep subscriber list synchronous.
There are a couple of WordPress plug-ins that do mass mailing. As an example, Mass Email To users. I am going to assume you've looked at them already. I have not used any of them.
What I used to use for an email list of 12,000 subscribers is use PHPList. It has an open source free version which allows you to send 300 messages a month and unlimited subscribers. It allows you to have subscribe/unsubscribe functions with the list and manage your subscribers without adding 1500 accounts to WordPress.
https://www.phplist.com
One of the issues to be aware of is that many ISPs have a 500 message per hour limitation per domain. This means that a list of 1500 people will take at least four hours to send. Why four hours? If you send 500 per hour, you might trip a daemon that blocks your website for using too many resources. Plus you can't receive any emails, since the cap is for every email. But if you dial down your send rate to 400, you should be fine. Even without a restriction, chances are it's going to take a while to send out a message to 1500 subscribers.
I moved onto a email provider like Mailchimp because at 450 emails per hour, it was taking 26+ hours to send an email and mailing list managers tend to be finicky. This gives you all your solutions on one server, which is nice when managing projects.
Good luck.
I've integrated Twilio for a client, but I need to incorporate their hours of operation. I know the sms messages have statuses, but how can I control the status when the message is created? I need the message to be created, but IF it's outside of hours of operation to NOT send the text... so put it in a queue... then when hours open again, send the text.
I see how I can query a sent message and see the status... but I want to specify the status and make sure it doesn't get sent until I specify when.
Please let me know how I can accomplish this. Thanks!
Megan from Twilio.
This is something you'll have to build into your application logic.
There are plenty of approaches you could take here such as scheduling a cron job or using a worker like Iron.io as seen in this post.
I hope this info helps.
I am using the Esendex Rest API http://developers.esendex.com/APIs/REST-API/inbox and I am trying to get all the messages in the inbox from a particular phone number.
This is basically so if I do a send out of SMS's and someone replies I am able to retrieve the reply.
I can currently get all the messages in the inbox into an array and sort them, but this is too slow with over 4000 messages.
Does anyone know if I can filter by phone number, or at least date-received in my API requests? Even if I could get the last weeks worth of SMS's.
You can try to use the conversation API if you want to filter by a phone number. The drawback is that you can get only the latest 15 messages, also that there is no reliable way to detect if a reply has been received from a phone number other than the inbox API. Apart from this I wasn't able to find anything that can help you. Their API is very restrictive and minimal.
There's currently no way to do this via the REST API but I'll see if we can add it over the next couple of weeks (I work for Esendex). As you note the functionality already exists in the Conversations API albeit in a more minimal form.
In the meantime you could achieve this by checking all messages that arrive either by polling the Inbox or using Push Notifications.