Slack API Message formatting - post

I would like to pass such a message through slack chat post API which will follow this format:
*Attention* where Attention word will be printed as bold with two stars before and after. But as slack itself considering * for formatting a word bold so the before after stars are not printing.
My script
$ch = curl_init("https://slack.com/api/chat.postMessage");
$data = http_build_query([
"token" => "*******",
"channel" => '#notifications-test',
"text" => '*Attention* `#channel` - Please inform the client. 75% of monthly hours have been used.'
]);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
Please help

Use "mrkdwn": false property. That would turn off auto formatting in Slack.

Related

Write requests are only supported on contained entities, Microsoft Graph API, Groups, PowerShell

I try to run the PS script, but receive an error "Write requests are only supported on contained entities", any ideas?
API Application permission access granted: GroupMember.ReadWrite.All, Group.ReadWrite.All, Directory.ReadWrite.All;
Access token well received;
PS:
function AddB2BToDisabledGroup (){
param(
[string]$AccessToken
)
$B2BAddToDisabledGroupHeaders = #{Authorization = "Bearer $AccessToken"}
$url = "https://graph.microsoft.com/v1.0/groups/$groupID/members/$ref"
$Body = #"
{
"#odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/$b2buserID"
}
"#
$addtogroupres = Invoke-RestMethod -Uri $url -Method Post -Headers $B2BAddToDisabledGroupHeaders -Body $Body -ContentType 'application/json' -ErrorAction Stop
$addtogroupres.status
}
Using the Tenant Admin account, using Graph Explorer, using the same group and user ID, POST works fine.
Tested also with:
"#odata.id": "https://graph.microsoft.com/v1.0/users/$b2buserID"

Monitoring connectivity for Slack and PagerDuty

We are using PRTG to monitor a number of internal resources, and we have set it up to alert us on a Slack channel and/or via PagerDuty (depending on severity) using their respective APIs. Considering that Slack and PagerDuty are external to us, we would also like to monitor whether our PRTG instance can access them -- basically, a form of self-monitoring or Who Watches the Watchmen?
So far the only reliable method we've found for Slack is to post an actual message to a private "testing" Slack channel, e.g. (Slack URL details redacted):
POST https://hooks.slack.com/services/XXX/YYY/ZZZ
Content-Type: application/json
{ "text": " ", "channel": "#prtg-webhook-test" }
Similarly, PagerDuty's Events API appears to be POST only, and the valid actions are limited to trigger, acknowledge, and resolve:
POST https://events.pagerduty.com/v2/enqueue
Content-Type: application/json
Is there a good way to test HTTPS connectivity without posting an actual Slack message / creating an actual PagerDuty alert? I couldn't find anything in documentation for either service, or a creative way to create an appropriate sensor in PRTG.
For Slack you might rather want to make an call to the API, not to a webhook.
I would recommend using auth.test, since its one of the few methods that has no rate limit.
Also, for the whole Slack service you can see the current status on this official webpage.
For pure connectivity, you can do a POST against the Events API with an empty payload, and you'll get an error message back:
curl --location --request POST 'https://events.pd-staging.com/v2/enqueue' \
--header 'Content-Type: application/json' \
--data-raw '{}'
{
"status": "invalid event",
"message": "Event object is invalid",
"errors": [
"'event_action' is missing or blank",
"'routing_key' must be provided in the body, or provided in the headers using 'x-routing-key'"
]
}
If you'd also like to validate your routing key, you can send an acknowledge event with a dummy dedup_key:
curl --location --request POST 'https://events.pd-staging.com/v2/enqueue' \
--header 'Content-Type: application/json' \
--header 'Cookie: uid=rBGA1lymclmSzRCsAwO3Ag==' \
--data-raw '{
"routing_key": "<your_routing_key>",
"event_action": "acknowledge",
"dedup_key": "something_that_will_never_match_an_open_incident"
}'
{
"status": "success",
"message": "Event processed",
"dedup_key": "something_that_will_never_match_an_open_incident"
}
Note that this will not show up anywhere in the PagerDuty UI, but that could be what you'd want anyways.

A value is required for property 'displayName' of resource 'Group'

Hello Everyone,
I am trying to fetch all the office 365 groups using MS Graph API by using PHP Curl.
Below is my code as,
$ch = curl_init('https://graph.microsoft.com/v1.0/groups');
curl_setopt_array($ch, array(
CURLOPT_HTTPHEADER => array('Authorization: Bearer '.$accessToken, 'Content-Type: application/json;'),
CURLOPT_RETURNTRANSFER =>true,
CURLOPT_VERBOSE => 1,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => json_encode(array('securityEnabledOnly'=>true))
));
$out = curl_exec($ch);
curl_close($ch); print_r($out);
OUTPUT:
{
"error": {
"code": "Request_BadRequest",
"message": "A value is required for property 'displayName' of resource 'Group'.",
"innerError": {
"request-id": "0961dd91-37ec-48d6-99bc-47f9e4b1d989",
"date": "2018-03-08T08:31:09"
}}}
I am using the same access token for fetching details by other MS Graph API's which are working fine but in this case, I get this error. Also, my tenant is approved for all users via admin consent.
Please help me in this as now I've no clue how to proceed.
The root of my issue (calling List Users) was that I was using POST and not GET, I see in the documentation that List Groups is supposed to be a GET as well. Using POST results in "A value is required for property '_______' of resource"

Not receiving push notifications if sending "data" (but "notification" works) payloads to GCM/FCM in iOS didReceiveRemoteNotification

I am trying to get "data" payload notifications to be received for our iOS app.
Today we can send GCM notification push notifications as according to:
https://developers.google.com/cloud-messaging/concept-options
(FCM has the same text)
An easy test is using CURL:
curl -X POST \
https://gcm-http.googleapis.com/gcm/send \
-H 'authorization: key=##_GCM_SERVER_ID_##' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: ##_POSTMAN_TOKEN_##' \
-d '{
"notification": {
"body": "Test body"
},
"to" : "##_DEVICE_TOKEN_##"
}
'
This will successfully trigger iOS AppDelegate.didReceiveRemoteNotification:fetchCompletionHandler function.
However, if change it to a data notification:
curl -X POST \
https://gcm-http.googleapis.com/gcm/send \
-H 'authorization: key=##_GCM_SERVER_ID_##' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: ##_POSTMAN_TOKEN_##' \
-d '{
"data": {
"body": "Test body"
},
"to" : "##_DEVICE_TOKEN_##"
}
'
I can't see anything is being sent to the app from GCM (in either didReceiveRemoteNotification functions), even if the app is in background/foreground.
Even though it says in the documentation it should:
https://developers.google.com/cloud-messaging/concept-options#notifications_and_data_messages
Note these further platform-specific details:
On Android, data payload can be retrieved in the Intent used to launch your activity.
On iOS, data payload will be found in didReceiveRemoteNotification:.
GCM can handle pure data push notifications to the APN network right?
Do I need to do anything special to receive data, compared to notification, Push Notifications in iOS?
When sending the Data type message with FCM to iOS devices, they will only be received if content_available is set to true in your FCM request body, eg:
{
"to": "--fcm-token--",
"content_available": true,
"data": {
"priority": "high",
"hello": "world"
}
}
Aside from the notes that you've shared, please don't miss out that,
On iOS, GCM stores the message and delivers it only when the app is in the foreground and has established a GCM connection.
With this, you may want to check Establishing a Connection. Then, when your XMPP connection is established, CCS and your server use normal XMPP <message> stanzas to send JSON-encoded messages back and forth. The body of the <message> must be:
<gcm xmlns:google:mobile:data>
JSON payload
</gcm>
Also, note that message_id is a required field for data message. Check this sample request format for message with payload - data message shown in Downstream Messages. You just have to convert it using CURL.
<message id="">
<gcm xmlns="google:mobile:data">
{
"to":"REGISTRATION_ID", // "to" replaces "registration_ids"
"message_id":"m-1366082849205" // new required field
"data":
{
"hello":"world",
}
"time_to_live":"600",
"delay_while_idle": true/false,
"delivery_receipt_requested": true/false
}
</gcm>
</message>
For more information, see XMPP Connection Server Reference.

Google oauth2 returns no id_token

I seem to miss something with oauth2. I get the access_token but not id_token!
I use the following to gain a google access_token by passing a "code" granted to me from https://accounts.google.com/o/oauth2/auth
$oauth2token_url = "https://accounts.google.com/o/oauth2/token";
$clienttoken_post = array(
"code" => $code,
"client_id" => $client_id,
"client_secret" => $client_secret,
"redirect_uri" => $redirect_uri,
"grant_type" => "authorization_code"
);
$curl = curl_init($oauth2token_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$json_response = curl_exec($curl);
curl_close($curl);
var_dump($json_response);
Everything seems to work but according to Google's documentation https://developers.google.com/accounts/docs/OAuth2Login#exchangecode I should be getting access_token, id_token, expires_in, token_type which I do except for the id_token
var_dump($json_response); shows the following:
string(126) "{ "access_token" : "ya29.AHES6ZSGlHVW9qA23xs8bHBP578Ef8S5cntJIcPT_SHWA", "token_type" : "Bearer", "expires_in" : 3598 }
What am I missing here?
At the token endpoint an id_token is issued only if certain scopes are present, the documentation should clarify that.
It is issued only if the email, profile or OpenID Connect scopes were used. An id_token does not make sense otherwise.
First, you need to add id_token for response_type.
Then you need to check scopes.
And don't forget that for implicit flow nonce param is required.
For more information and example you can check:
http://openid.net/specs/openid-connect-core-1_0.html#ImplicitAuthRequest

Resources