Trying to read "bounce list" from AWS SNS in PHP - aws-php-sdk

I'm programming an application to send emails through Amazon SES.
I would like to read the bounces (hard/soft bounces) from Amazon SNS (SES and SNS are already linked).
I tried the code shared on StackOverflow, but i constantly get an error message
//Create a SESClient
$SnsClient = new Aws\Sns\SnsClient([
//'profile' => 'default',
'version' => '2010-03-31',
'region' => 'eu-west-1',
'credentials' => [
'key' => $DatabaseLink->aws_access_key_id,
'secret' => $DatabaseLink->aws_secret_access_key],
]);
try {
$_SERVER['HTTP_X_AMZ_SNS_MESSAGE_TYPE'] = 'Notification';
// Retrieve the message
$message = Message::fromRawPostData();
// make validator instance
$validator = new MessageValidator();
// Validate the message
if ($validator->isValid($message)) {
if ($message['Type'] == 'SubscriptionConfirmation') {
// if it's subscription or unsubscribe event then call SubscribeURL
file_get_contents($message['SubscribeURL']);
} elseif ($message['Type'] === 'Notification') {
$subject = $message['Subject'];
$messageData = json_decode($message['Message']);
// use $subject and $messageData and take relevant action
}
}
} catch (Exception $e) {
// Handle exception
echo $e;
}
"Invalid POST data". I don't want to send a message for validation, i would like to get the list of email adresses that bounced. So, my backend can process them and remove them from my database.
Could you please help me to figure it out?
I'm going in circles with the aws documentation.

Related

Twilio\Exceptions\RestException: [HTTP 400] Unable to create record: Cannot CREATE credentials record

I am getting an error when I try to create a Twilio Push Notification credential using Rest Api for my Subaccount in Twilio , Here is the response :
Twilio\Exceptions\RestException: [HTTP 400] Unable to create record: Cannot CREATE credentials record. 'Secret' must be present in file /home/forge/qc.cp.iocod.com/vendor/twilio/sdk/src/Twilio/Version.php on line 85
My code is
$sub_account = new TwilioClient('ACxxxxxxxxxxxxxxxxxx6f4', '7exxxxxxxxxxxxxxxxxxxx');
if( $sub_account)
{
$variable = $sub_account->notify->v1->credentials->create([
"type" => 'fcm',
"secret" => 'AxxxxI:APA91bG-WY6p9jNuTtgX5SohRF4VviARCjz68FIxvpTIeYUexxxxxxxxx',
]);
if( $variable)
{
echo $variable->sid;
}
}
Please cross-check your second parameter, the First parameter should be type, and the second parameter should be an array of secret
Finally, I got the solution
$variable = $sub_account->notify->v1->credentials->create('fcm',["secret" =>'Your_FCM_TOKEN',]);
if( $variable)
{
echo $variable->sid;
}

Not recieving sms using twilio notify service, no debug error in console?

I am trying to send bulk SMS using Twilio notify API. I had looked at the documentation, and other StackOverflow resources but did not find the issue yet. What I am doing is:
$sid = "AC1e590cbb8eee064c3c71axxxxxxxxxxx";
$token = "94c2dc3e2e407c4ebd28cxxxxxxxxxxx";
$twilio = new Client($sid, $token);
$serviceSid = "IS32913ae9b083b809b1c06xxxxxxxxxxx";
$recipients = array();
foreach($phone_nos as $phone_no) {
array_push($recipients, $phone_no['phone_no']);
}
//recipients array print value is
//Array
//(
//[0] => +923105653361
//[1] => +923491457062
//)
$binding = array();
foreach ($recipients as $recipient) {
$binding[] = '{"binding_type":"sms", "address":"'.$recipient.'"}';
}
//binding array is print value is
//Array
//(
//[0] => {"binding_type":"sms", "address":"+923105653361"}
//[1] => {"binding_type":"sms", "address":"+923491457062"}
//)
$service = $twilio->notify->v1->services->create();
$notification = $twilio->notify->services($serviceSid)
->notifications->create([
"toBinding" => $binding,
"body" => 'Test message 5 notify'
]);
echo $notification->body;
echo '<pre>';print_r($notification->sid);exit;
The notify console is showing the messages are sent with no error.
Twilio developer evangelist here.
It looks like you haven’t connected a messaging service and a phone number to your Notify service. Follow the instructions in the documentation here to set that up, then try sending the messages again.

Twilio Classic Functions, How do you work with Tags and SMS?

Twilio function Problem: Tags are not working as expected.
I'm trying to create unique SMS subscription lists for users who SMS 'keyword1','keyword2','keyword3',etc to my number.
I'm doing this by intercepting the 'incoming message' events via a classic function.
I want to poll the keywords then assign tags to the users as I subscribe them to a list.
Then when I broadcast SMS I want to be able to send to only those users who are tagged with my keyword.
For example to capture the keyword 'test' and assign the tag 'test' to a user, I'm using the code below.
And then to send messages to all users with the tag 'test' I'm using a "sendtest" command.
I can broadcast to 'all' tags and it will work fine, but if I want to only send to users with tags ['test'], then there are no errors reported and the system tells me it was successful, but no subscribers will receive any messages.
I'm wondering if I have some problem in the way I am trying to define the tags? It looks like the data format is supposed to be a STRING[] array of some kind, I'm guessing ['test','two','three']. (If I can confirm this is right). But I notice as per the working examples provided by twilio if I set the notification arguments to a string IE: tags: 'all', then this syntax works to broadcast to all tags. Anything else though, will not work at all.
is there some trick to getting tags to work, or do they not work at all when trying to filter notifications via the classic function interface?
class TestCommand extends Command {
run(callback) {
// Create a new SMS Notify binding for this user's phone number
//and try to tag the user with keyword 'test'
notify.bindings.create({
identity: this.fromNumber,
bindingType: 'sms',
address: this.fromNumber,
tags: ['test']
}).then((response) => {
callback(null, 'test Message success')
}).catch(err => {
callback(err, 'test message fail')
})
}
}
class BroadcastTestCommand extends Command {
run(callback) {
// Check if sender is in list of admins, stored in the system environment
// as a comma-separated string
if (adminNumbers.indexOf(this.fromNumber) < 0) {
return callback(null, 'broadcast Not Authorized')
}
// Create a new SMS Notify binding for this user's phone number
//only notify users who are tagged with 'test'
notify.notifications.create({
tag: ['test'],
body: this.commandText
}).then((response) => {
callback(null, 'broadcast test Success')
}).catch(err => {
console.log(err)
callback(err, 'broadcast test Fail')
})
}
}
// Handle incoming SMS commands ####################
exports.handler = (context, event, callback) => {
// Get command text from incoming SMS body
let cmd = event.Body || ''
cmd = cmd.trim().split(' ')[0].toLowerCase()
// Default to help command
let cmdInstance = new HelpCommand(event, context)
// Choose other commands as appropriate
switch(cmd) {
case 'test': cmdInstance = new TestCommand(event, context); break;
case 'sendtest': cmdInstance = new BroadcastTestCommand(event, context); break;
}
// Execute command
cmdInstance.run((err, message) => {
let twiml = new twilio.twiml.MessagingResponse()
if (err) {
console.log(err)
message = 'There was a problem with your request. Try again!'
}
twiml.message(message)
callback(null, twiml)
})
}
Okay for anyone else pulling their hair out on this one..
The Twilio docs here on bindings will throw you off
https://www.twilio.com/docs/notify/api/binding-resource
Because the argument is NOT 'tags' it's 'tag'
This works ...
class TestCommand extends Command {
run(callback) {
// Create a new SMS Notify binding for this user's phone number
//and try to tag the user with keyword 'test'
notify.bindings.create({
identity: this.fromNumber,
bindingType: 'sms',
address: this.fromNumber,
tag: ['test']
}).then((response) => {
callback(null, 'test Message success')
}).catch(err => {
callback(err, 'test message fail')
})
}
}

How to subscribe to and see events from Hyperledger Composer transactions

I am running an NodeJS server with the following code to connect to the Hyperledger Runtime:
const BusinessNetworkConnection = require("composer-client")
.BusinessNetworkConnection;
this.businessNetworkConnection = new BusinessNetworkConnection();
this.CONNECTION_PROFILE_NAME = "hlfv1";
this.businessNetworkIdentifier = "testNetwork";
this.businessNetworkConnection
.connect(
this.CONNECTION_PROFILE_NAME,
this.businessNetworkIdentifier,
"admin",
"adminpwd"
)
.then(result => {
this.businessNetworkDefinition = result;
console.log("BusinessNetworkConnection: ", result);
})
.then(() => {
// Subscribe to events.
this.businessNetworkConnection.on("events", events => {
console.log("**********business event received**********", events);
});
})
// and catch any exceptions that are triggered
.catch(function(error) {
throw error;
});
I see data returned after the connection has been made in the result object and it is the correct network data that has been deployed.
However, when I submit transactions and made request VIA my generated REST APIs no events are seen by my server. In the Historian, I can see that events are emitted. Is there something else that I should be doing to see those events emitted by my transactions?
I tried same kind of test and I could receive events. I compared my test code and yours, and I found following difference:
this.bizNetworkConnection.on('events'
this.bizNetworkConnection.on('event'
I hope it helps.

Why i don't see my #replies in conversation view in twitter?

I need to reply to one particular twitter status. I'm using following functions. And I've used Abraham's twitteroauth library in php.
public function replyToTwitterStatus($user_id,$status_id,$twitt_reply,$account_name)
{
$connection= $this->getTwitterConnection($user_id,$account_name);
try{
$responce = $this->postApiData('statuses/update', array('status' => $twitt_reply,'in_reply_to_status_id '=> $status_id),$connection);
}
catch(Exception $e){
echo $message = $e->getMessage();
exit;
}
}
// this function will handle all post requests
// To post/update twitter data
// To post/update twitter data
public function postApiData($request,$params = array(),$connection)
{
if($params == null)
{
$data = $connection->post($request);
}
else
{
$data = $connection->post($request,$params);
}
// Need to check the error code for post method
if($data->errors['0']->code == '88' || $data->errors['0']->message == 'Rate limit exceeded')
{
throw new Exception( 'Sorry for the inconvenience,Please wait for minimum 15 mins. You exceeded the rate limit');
}
else
{
return $data;
}
}
But the issue is that it is not maintaining the conversation view and it is update like normal status for e.g #abraham hello how are you. but that "View conversation" is not coming. Like expanding menu is not coming.
Please do needful
Thanks
You've got an unwanted space in your in_reply_to_status_id key which causes that parameter to be ignored.
This call:
$responce = $this->postApiData('statuses/update', array(
'status' => $twitt_reply,
'in_reply_to_status_id ' => $status_id
), $connection);
should look like this:
$responce = $this->postApiData('statuses/update', array(
'status' => $twitt_reply,
'in_reply_to_status_id' => $status_id
), $connection);
Also, make sure that the $status_id variable is being handled as a string. Although they look like numbers, most ids will be too big to be represented as integers in php, so they'll end up being converted to floating point which isn't going to work.
Lastly, make sure you have include the username of the person you are replying to in the status text. Quoting from the documentation for the in_reply_to_status_id parameter:
Note:: This parameter will be ignored unless the author of the tweet this parameter references is mentioned within the status text. Therefore, you must include #username, where username is the author of the referenced tweet, within the update.

Resources