How To Send GCM Message More Then 1000 users in one time - google-cloud-messaging

I am new to php and GCM. i am using following code to send gcm message using php and mysqldb as i am getting notification successfully however the android guidelines state that gcm message should be send in batch of 1000 each so i am looking for a solution so i can send notification in chunks so all user will receive the notification. i have seen some answers on some similar question but no one seems to be as much detailed for a beginner.
My question is that how i will be able to send GCM message more then 1000 user in one time as i have more then 20,000 users in my scenario. how i will be able to make 1000
Below Is The Code
<?php
include_once 'db_functions.php';
$db = new DB_Functions();
$appId= $_POST["appIdSelect"];
if($appId==0)
{
echo "App not selected, Please choose app first!!";
return;
}
$users = $db->getAllDevicesByAppId($appId);
$message = $_POST["message"];
$message = array("alert" => $message);
$i=0;
while ($row = mysql_fetch_array($users)) {
$regId = $row["device_id"];
//$regId."<br/>";
include_once './GCM.php';
$gcm = new GCM();
$registatoin_ids = array($regId);
$result = $gcm->send_notification($registatoin_ids, $message);
$result;
$i++;
}
echo "Notification send to APP ID= ".$appId." successfully. Total notification sends = ".$i;
?>

The 1000 limit is for when using the registration_ids parameter.
For your scenario, it is suggested to make use of Topic Messaging. Depending on which platform your users are, you simply have to have them subscribe to your topic, and as soon as you send a message to that topic, all subscribers will receive that message.
With all that said, is there a reason why you're not using the newer version of GCM which Firebase Cloud Messaging (FCM)?

Related

bot.telegram.getChat does not return the message of a specific user

I am trying to setup my bot so that it will 'listen' to a specific user and print out any incoming message.
I have already setup a bot in telegram using BotFather. This is what I have so far
const { Telegraf } = require('telegraf')
const bot = new Telegraf('my_bot_token_here');
bot.telegram.getChat(Chat_Id).then(function(chat) {
console.log('chat info', chat);
});
The object does not contain the user message.
Any advice on this is appreciated.
Yes, absolutely. You need to check the 'from' field in the message before executing your logic.
Telegram API

How to find user's email ID? - Google Oauth2 API PHP Client

I am implementing an Audio library manager which uses user's google drive as backend storage. I am using PHP (google-api-php-client-2.2.1) to get the user's authorization for accessing his/her google drive.
So far I am able to receive access token and refresh token using example code from google (https://developers.google.com/api-client-library/php/auth/web-app), and also tested by listing files of user's google drive.
However, I am not able to figure out programmatically which user has given authorization to my application. Just user's email address will do. I don't need any other information.
I am using the following code.
<?php
require_once 'google-api-php-client/vendor/autoload.php';
session_start();
$client = new Google_Client();
$client->setAuthConfig('client_secret.json'); //downloaded from google oauth credentials portal. It includes redirect URL
$client->setAccessType("offline"); // offline access
$client->setIncludeGrantedScopes(true); // incremental auth
$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);
if (! isset($_GET['code'])) {
//Get authorization and User consent from Google
$auth_url = $client->createAuthUrl();
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
} else { //Authorization completed
//Get access token
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$_SESSION['refresh_token'] = $client->getRefreshToken();
echo "Access Token<br>";
var_dump ($_SESSION['access_token']); //works
echo "<br>";
echo "Refresh Token<br>";
var_dump ($_SESSION['refresh_token']); //works
echo "<br>";
$service=new Google_Service_Oauth2($client);
echo "Auth2 Service created<br>"; //Getting this print
$usr_info=$service->userinfo;
echo "User Info<br>"; //Getting this print
var_dump ($usr_info); //Getting this print, Very long JSON structure. But info is mostly pertaining to my app...no user information showing here
echo "<br>";
//$usr_info_get = $usr_info->get(); //Throwing Error
//$usr_info_get = $usr_info->get(['email']); //Throwing Error
//$usr_info_get = $usr_info->get()['email']; //Throwing Error
echo "User Info Get<br>";
//var_dump ($usr_info_get);
echo "<br>";
}
?>
The class for userInfo is like this
class Google_Service_Oauth2_Resource_Userinfo extends Google_Service_Resource
{
/**
* (userinfo.get)
*
* #param array $optParams Optional parameters.
* #return Google_Service_Oauth2_Userinfoplus
*/
public function get($optParams = array())
{
$params = array();
$params = array_merge($params, $optParams);
return $this->call('get', array($params), "Google_Service_Oauth2_Userinfoplus");
}
}
The params for get() method should be optional, but
$userInfo->get()
also given me Server Error.
I am not finding anything else from my google search on this.
I tried this (6 year old thread) but code errors out (apiHttpRequest class not found)
How to identify a Google OAuth2 user?
I tried reading about openID but seems kinda complex. Also, not sure if google-api-php-client has helper class for openID.
I would really appreciate your help. Already spent 2+ days reading google api client php code but now up against the wall.

how send video note in telegram bot?

can any body help me to send video not in telegram bot؟
In fact, my problem is that when sending a video note is not sent in a circle.
And it's sent as ordinary as sending a normal video.
I followed all the necessary points are posted the video.
I uploaded the file in :
Mp4 format
Less than a minute
And is square.
And the code I've used:
the main function :
define('API_KEY','Token');
function bot($method,$datas=[]){
$url = "https://api.telegram.org/bot".API_KEY."/".$method;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($datas));
$res = curl_exec($ch);
if(curl_error($ch)){
var_dump(curl_error($ch));
}else{
return json_decode($res);
}
};
send video note :
bot("sendVideoNote",[
"chat_id"=>$chat_id,
"video_note"=>$video_file_id,
]);
And with the place of this variable video_file_id ["file_id"], I used the direct address of the files, but I did not get any results in bot.
thanks for your helping...
As stated in the Telegram Bot Api:
Sending video notes by a URL is currently unsupported.
This leads to video notes that are passed by an URL to be displayed as normal videos.
However, you can upload the file directly to create a real video note. Using CURLFile it would work as following:
$path = "path/to/video.mp4";
$realpath = realpath($path);
bot("sendVideoNote",[
"chat_id" => $chat_id,
"video_note"=> new CURLFile($realpath))
]);

Why Icinga2 telegram notification fails in specific services?

I have created custom telegram notification very similar to email notifications. The problem is that it works for hosts and most of the services but not for all of them.
I do not post the *.sh files in scripts folder as it works!
In constants.conf I have added the bot token:
const TelegramBotToken = "MyTelegramToken"
I wanted to manage telegram channels or chat ids in users file, so I have users/user-my-username.conf as below:
object User "my-username" {
import "generic-user"
display_name = "My Username"
groups = ["faxadmins"]
email = "my-username#domain.com"
vars.telegram_chat_id = "#my_channel"
}
In templates/templates.conf I have added the below code:
template Host "generic-host-domain" {
import "generic-host"
vars.notification.mail.groups = ["domainadmins"]
vars.notification["telegram"] = {
users = [ "my-username" ]
}
}
template Service "generic-service-fax" {
import "generic-service"
vars.notification["telegram"] = {
users = [ "my-username" ]
}
}
And in notifications I have:
template Notification "telegram-host-notification" {
command = "telegram-host-notification"
period = "24x7"
}
template Notification "telegram-service-notification" {
command = "telegram-service-notification"
period = "24x7"
}
apply Notification "telegram-notification" to Host {
import "telegram-host-notification"
user_groups = host.vars.notification.telegram.groups
users = host.vars.notification.telegram.users
assign where host.vars.notification.telegram
}
apply Notification "telegram-notification" to Service {
import "telegram-service-notification"
user_groups = host.vars.notification.telegram.groups
users = host.vars.notification.telegram.users
assign where host.vars.notification.telegram
}
This is all I have. As I have said before it works for some services and does not work for other services. I do not have any configuration in service or host files for telegram notification.
To test I use Icinga web2. Going to a specific service in a host and send custom notification. When I send a custom notification I check the log file to see if there is any error and it says completed:
[2017-01-01 11:48:38 +0000] information/Notification: Sending reminder 'Problem' notification 'host-***!serviceName!telegram-notification for user 'my-username'
[2017-01-01 11:48:38 +0000] information/Notification: Completed sending 'Problem' notification 'host-***!serviceName!telegram-notification' for checkable 'host-***!serviceName' and user 'my-username'.
I should note that email is sent as expected. There is just a problem in telegram notifications for 2 services out of 12.
Any idea what would be the culprit? What is the problem here? Does return of scripts (commands) affect this behaviour?
There is no Telegram config in any service whatsoever.
Some telegram commands may fail due to markdown parser.
I've encountered this problem:
If service name has one underscore ('_'), then parser will complain about not closed markdown tag and message will not be sent

Google API Client Libraries -PHP : Google Game Services occurs error (code : 500) without any message

I'm using Google API Client Libraries - PHP and using Service accounts issuing on Google API Console.
I want to get Leaderboards list but error occurs code 500 without any message.
Enabled Google Play Game Management, Google Play Game Services, Google+ API on API Console.
And, Android application using this Leaderboards proper.
What can I do resolve this problem?
request codes(PHP)
set_include_path(get_include_path().PATH_SEPARATOR.'/path/to/google-api-php-client/src');
require_once realpath(dirname(__FILE__).'/google-api-php-client/src/Google/autoload.php');
$client_email = 'myaccount#developer.gserviceaccount.com';
$private_key = file_get_contents('/path/to/my_key_file.p12');
$scopes = array(
Google_Service_Games::GAMES,
Google_Service_Games::PLUS_LOGIN
);
$client = new Google_Client();
$credentials = new Google_Auth_AssertionCredentials(
$client_email,
$scopes,
$private_key
);
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
$service = new Google_Service_Games($client);
$response = $service->leaderboards->listLeaderboards();
echo json_encode($response) . "\n";
error occours
Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/games/v1/leaderboards: (500) {
"error": {
"code": 500,
"message": null
}
}
Additional, It is works simple query - like Book API, returned proper results without error...
$service = new Google_Service_Books($client);
$optParams = array('filter' => 'free-ebooks');
$results = $service->volumes->listVolumes('Korea', $optParams);
var_dump($results) ;
Let me know your any advice.
Thank you for your help. :)