Android GCM collapse even if with different collapse keys - php

I'm using this lib to send two different messages with different collapse keys, but on my device I'm receiving the first and then the second is coming over the first.
I would like to have the two separately in the Android notification header on device.
For the record I'm using this Phonegap plugin to receive the push notification.
Here is my code:
$gcmApiKey = 'api key here';
$deviceRegistrationId = 'device regid here';
$numberOfRetryAttempts = 5;
$collapseKey = '1';
$payloadData = ['title' => 'First Message Title', 'message' => 'First message'];
$sender = new Sender($gcmApiKey);
$message = new Message($collapseKey, $payloadData);
$result = $sender->send($message, $deviceRegistrationId, $numberOfRetryAttempts);
// Sending Second message
$collapseKey = '2';
$payloadData = ['title' => 'Second Message Title', 'message' => 'Second Message'];
$sender = new Sender($gcmApiKey);
$message = new Message($collapseKey, $payloadData);
$result = $sender->send($message, $deviceRegistrationId, $numberOfRetryAttempts);

If I understand you right, your problem is that the first notification is replaced by the second after it was shown.
If that is the case, your mistake is not on the PHP-side here, but in your Java-code.
If you show a notification you call this method:
NotificationManager.notify(int id, Notification notification)
Most likely, you are setting the id parameter to the same value each time you call this method.
The effect of the id is that the system will only show one notification with the same ID - the newest. A typical use-case to use the same id as before would be to update a previous notification.
If you want to display multiple notifications, you need to set a different id each time. You could use a random number or better yet use a previously defined ID of your content.
The GCM collapse key has a different effect:
When you define a collapse key, when multiple messages are queued up in the GCM servers for the same user, only the last one with any given collapse key is delivered.
That means, for example, if your phone was off, you would only receive one message with the same collapse key. It doesn't do anything if your phone receives the first notification before you send the second.
To set it with your PhoneGap plugin
The plugin has a really messy documentation but if we look into the source code, we'll find this undocumented feature:
int notId = 0;
try {
notId = Integer.parseInt(extras.getString("notId"));
}
mNotificationManager.notify((String) appName, notId, mBuilder.build());
That means, if you change your payload to, for example:
$payloadData = ['title' => 'First Message Title', 'message' => 'First message', 'notId' => mt_rand()];
your notifications won't replace each other.

Related

can we fetch email from inbox and sentbox in one call (gmail API PHP)

i'm using Gmail API to fetch messages. if i do like this
$labelIds = ['INBOX'];
$opt_params=[
'labelIds' => $labelIds,
];
$list = $gmail->users_messages->listUsersMessages('me',$opt_params);
it will work fine. and return messages. but if i mention SENT label with INBOX then it return nothing. what am i doing wrong?
$labelIds = ['INBOX', 'SENT'];
i want to fetch emails from both inbox and sentbox in one call.
Your code lists messages that has both the INBOX and SENT labels. You can list messages that has either one with the OR operator:
$opt_params=[
'maxResults' => 50,
'q' => 'in:inbox OR in:sent',
];
$list = $gmail->users_messages->listUsersMessages('me', $opt_params);

Telegram: add callback data to reply_markup

I am trying to add callback data to reply_markup.
This is my code:
$option[] = array("test");
$replyMarkup = array('keyboard'=>$option,'one_time_keyboard'=>false,'resize_keyboard'=>true,'selective'=>true);
$encodedMarkup = json_encode($replyMarkup,true);
This code sends TEST to button and a call back to server TEST string for case
But I want use TEST string to show user and call back to server by KEY
This code does not work for me:
$option[] = array("text"=>"test","call_back"=>"key");
It looks you try to use ReplyKeyboardMarkup. It defines a keyboard with templates of messages which an user can send by tapping on a button.
But you want to get specific key so take a look at InlineKeyboardMarkup for this.
$options[][] = array('text' => 'Your text', 'callback_data' => 'test-data');
$replyMarkup = array('inline_keyboard' => $options);
$encodedMarkup = json_encode($replyMarkup, true);
When an user presses the button, your bot will receive a special update, CallbackQuery.

how to replace text with another similar to mail merge?

I am working in Magento, and i have developed a module to send text messages to customers. In the settings of the module, the admin can set the message that will be sent to the customer. I'm trying to add a features that will allow the replacement of texts with data from my database.
for example, i currently have the following code that fetches the saved settings for the body of the text message:
$body = $settings['sms_notification_message'];
The message that is fetched looks like this:
Dear {{firstname}},
your order ({{ordernumber}}) has been shipped.
tracking#: {(trackingnumber}}
Thanks for your business!
{{storename}}
The goal is to have the module replace the variables in "{{ }}" with the customer and store information.
Unfortunately, i'm unable to figure out how to make it replace the information before sending the message. It is currently being send as is.
The easiest way to do it would be to use str_replace, like so:
// Set up the message
$message = <<< MESSAGE
Dear {{firstname}},
your order ({{ordernumber}}) has been shipped.
tracking#: {{trackingnumber}}
Thanks for your business!
{{storename}}
MESSAGE;
// Assign the values in an associative array
$values = [
'firstname' => 'firstnamevalue',
'ordernumber' => 'ordernumbervalue',
'trackingnumber' => 'trackingnumbervalue',
'storename' => 'storenamevalue'
];
// Create arrays $target indicating the value to change
$targets = [];
foreach ($values as $k => $v) {
$targets[] = '{{'.$k.'}}';
}
// Use str_replace to perform the substitution
echo str_replace($targets,$values,$message);

How can i get campaign's web id when campaign is created using API in Mailchimp?

I am using API version 1.3 of mailchimp to create Campaign programmatically in PHP.
I am using MCAPI class method campaignCreate() to create campaign. Campaign is created successfully and it returns campaign id in response which is string.
But i need Web id (integer value of campaign id) so that I can use it to open that campaign using link on my website.
For example: lets say I want to redirect user to this link - https://us8.admin.mailchimp.com/campaigns/show?id=941117 and for that i need id value as 941117 when new campaign is created.For now i am getting it as string like 6ae9ikag when new campaign is created using mailchimp API
Please let me know if anyone knows how to get campaign web id (integer value) using Mailchimp API in PHP
Thanks
I found an answer so wanted to share here.Hope it helps someone
I get campaign id as a string when createCampaign() method of MCAPI class is used.
You need to use below code to get web id (integer value of campaign id)
$filters['campaign_id'] = $campaign_id; // string value of campaign id
$campaign = $api->campaigns($filters);
$web_id = $campaign['data'][0]['web_id'];
This worked for me.
Thanks
<?php
/**
This Example shows how to create a basic campaign via the MCAPI class.
**/
require_once 'inc/MCAPI.class.php';
require_once 'inc/config.inc.php'; //contains apikey
$api = new MCAPI($apikey);
$type = 'regular';
$opts['list_id'] = '5ceacbda08';
$opts['subject'] = 'Test Newsletter Mail';
$opts['from_email'] = 'guna#test.com';
$opts['from_name'] = 'guna';
$opts['tracking']=array('opens' => true, 'html_clicks' => true, 'text_clicks' => false);
$opts['authenticate'] = true;
$opts['analytics'] = array('google'=>'my_google_analytics_key');
$opts['title'] = 'Test Newsletter Title';
$content = array('html'=>'Hello html content message',
'text' => 'text text text *|UNSUB|*'
);
$retval = $api->campaignCreate($type, $opts, $content);
if ($api->errorCode){
echo "Unable to Create New Campaign!";
echo "\n\tCode=".$api->errorCode;
echo "\n\tMsg=".$api->errorMessage."\n";
} else {
echo "New Campaign ID:".$retval."\n";
}
$retval = $api->campaignSendNow($retval);
?>
The web_id is returned by mailchimp when a call is made to the creation end point.
$mcResponce = $mailchimp_api->campaigns->create(...);
$web_id = $mcResponce['web_id'];
See the documentation.

Zendesk php api create ticket without sending email to the user?

I am trying to create tickets on my Zendesk and that is working fine. However i do not want Zendesk to email the creator of the tickets (his or her email). Is this possible?
The idea is i have a contactForm widget on my site, i want the submits from this form to create tickets in my Zendesk.
Creating tickets is currently working using this code:
$zendesk = new zendesk(
$row->api_key,
$row->email_address,
$row->host_address,
$suffix = '.json',
$test = false
);
$arr = array(
"z_subject"=>"Offline Message",
"z_description"=> $r->contact_msg,
"z_recipient"=>$r->contact_email,
"z_name"=>$r->contact_name,
);
$create = json_encode(
array('ticket' => array(
'subject' => $arr['z_subject'],
'description' => $arr['z_description'],
'requester' => array('name' => $arr['z_name'],
'email' => $arr['z_requester']
))),
JSON_FORCE_OBJECT
);
$data = $zendesk->call("/tickets", $create, "POST");
Any ideas?
Totally possible! You need to add some conditions to the trigger "Notify requester of received request" in Zendesk - Trigger setting to prevent zendesk from sending email. For ex:
Ticket : Channel - Is Not - Webservice (API)
Ticket : Tags - Contains one of the following - "offline message"
You could use another API endpoint "Ticket Import" https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_import/
It's do not send notifications

Categories