sending message to slack channel using PHP/Guzzle prints "Array" - php

I'm trying to post to a Slack channel but it's not working as intended.
The only message I get in Slack says Array, as in that the value of text is an Array. As I'm understanding their docs, it shouldn't do that. If I move the text to the first level of the array, the actual text is displayed, so I'm guessing that my request is working fine. What am I missing? This is being done in PHP with GuzzleHttpClient.
My message:
[
'type' => 'section',
'text' => [
'type' => 'mrkdwn',
'text' => 'This is supposed to be my text'
]
];
My request to the API:
$request = $client->post($url, [
RequestOptions::JSON => $messages
]);

It seems not as obvious, but you cannot use the message formatting used for their API chat.postMessage for incoming webhooks. Both have different formatting.
With that said, follow this documentation for webhook messages and it's respective formatting here.
What you were trying to do is use so called "blocks" which seems to be dedicated to their API messaging instead.
If you try your message on this message builder (which is intended for webhooks), it will fail. But it will work on this message builder.
Perhaps you can get away with using new-lines if you want your message to appear over multiple lines. See here.

As #ncla mentioned, if you are using "Block UI" elements, using the incoming webhook API, you cant send the blocks as with the chat.postMessage.
Its not obvious on the Blocks documentation, but in the
Messages payload page it specifies that you can send a blocks attribute. This will allow you to use the Blocks structure.

Your structure is incorrect, see documentation: https://api.slack.com/messaging/composing/layouts#stack-of-blocks
It should be array of message blocks, you need to nest it further one time.
[
[
'type' => 'section',
'text' => [
'type' => 'mrkdwn',
'text' => 'This is supposed to be my text'
]
]
];

Related

Mailchimp API (3.0.75 for PHP) invalid resource issue on updateListMemberTags

I have a situation where I am importing lists of people from a CRM and then assigning a tag to help group them in Mailchimp. The importing works no problem, but I get an Invalid Resource error when I try to add the tag using this code:
$response_updateListMemberTags = $mailchimp->lists->updateListMemberTags("91ca711dd8", md5($row->Eaddress_HH_A1_A2), [
"tags" => [
["name" => $iListID, "status" => "active"]
]);
The Guzzle exception message is
Invalid Resource - The resource submitted could not be validated.
The super odd thing is that if I output the above to the screen, and then copy and paste that output into the code to run, it works. I just can't wrap my brain around it. Thoughts?

How to fill campaign template with repeatablecontent via Mailchimp Marketing API

I have campaing which uses template and I need to send this campaign via Marketing API with 5 (or more) latest job offers. I trying to find the way to do it.
I've tried to use Template Language on simple example.
I've added this block to template: <h3 mc:edit="article_title">Title</h3>
And then I try to update campaign content with PHP library mailchimp/marketing:3.0.27:
$campaign = $this->mailchimp->campaigns->setContent($campaignId, [
'template' => [
'id' => (int) $templateId,
'sections' => [
'article_title' => 'Test title',
],
],
]);
This request runs successfully, but I don't see any changes in response, campaing design or test email.
What I doing wrong? Or maybe there is another way to solve my problem?
I also tried to ask Mailchimp support about this problem, but got no answer.
The truth is that this feature was not implemented and will not work.

How to send AWS SMS messages to multiple phone numbers in PHP Laravel

I've managed to get my SNS service working in PHP laravel but the issue I have is that I can only send to one number.
I've used the following:
$sms = AWS::createClient('sns');
$sms->publish([
'Message' => $content,
'PhoneNumber' => '+123456789',
'MessageAttributes' => [
'AWS.SNS.SMS.SMSType' => [
'DataType' => 'String',
'StringValue' => 'Transactional',
]
],
]);
The phone number has to be a string, I really do not want to put this inside a for loop for each number and I can't find anything using PHP specifically about sending to multiple phone numbers. Any help would be appreciated!
Hey guys so for anyone interested I managed to find a way to do this. I create a Job queue which I passed the array of phone numbers as well as the content of the message, and then in the handle method in the job just looped through the phone numbers with my above method and it worked perfectly.

Laravel Push notifications: Send silent push notification

I am using this to send push notification to iOS and it is working fine except the fact that I don't know how to send a silent push using this package. I have tried to send it like this:
$payload = PushNotification::Message('', array(
'aps' => array(
'content_available' => 1,
),
'data' => array(
'actionType' => $actionType
)
));
Sending empty string in the first param of ::Message, it does not show anything on mobile screen but it does produces the sound. Secondly, I tried it without the presence of this param. But if this param is not present, it throws exception. How to send silent push? Any ideas?
My Laravel version is 5.4.
Such a trivial mistake that I made in the code shown above in the question is to use content_available instead of content-available.

ALL GCM parameters?

i´ve written a "pushserver" for my app via PHP.
The push notifications i´ve sent via PHP are all received on the device, so far.
But, i can just send/set the "message" and "title", see:
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array(
'message' => $message,
'title' => 'My App',
'vibrate' => 1,
'sound' => 1,
'icon' => "http://example.com/image.jpg",
"style" => "inbox"
),
);
"icon" and "style" are not working (vibrate and sound not tested, yet).
Every link for the parameters i´ve found is broken or kind of "you need to do object.setSomething() in JAVA.
Is there a list anywhere where i can see ALL parameters, which i can send to GCM? No matter, what language i use?
Cheers,
Chris
couple of things need to keep in mind while all the data which you sending from server end
Is there a list anywhere where i can see ALL parameters,
exp :- you can send as many parameters as you want but offcourse there is limitation but not key specific just like you can use "textmessage" instead of "message" but make sure to retrieve the value from same key which you are assigning from server end
1) please make sure that you are getting all the data in gcmintentservice class try to print the log of all intent data.
please remember that this is just a string data it is not going to download the image for you. you have to download using volley library or any suitable library

Categories