How to notify specific people with yammer REST api - yammer

I would like to notify a specific set of people when posting a message with Yammer's REST API. The desired effect should be the same as "Add people to notify" in the native web application:
After some research with the REST API documentation, i found the direct_to_id field in the request data object.
direct_to_id - Send a private message directly to the user indicated.
I'm not sure what this attribute actually does, so I tried the following:
var data = {
"body": "test message",
"group_id": XXXXXX, //a valid group id
"direct_to_id": XXXXXXXXXX, //a valid user id
};
but after I add the "direct_to_id" field to my post, i get a 400 (bad request) error. I also don't know if this method works with notifications to multiple users.

Ok, i figured it out by reverse engineering the yammer embed widget. When posting a message with people to be notified, yammer embed set a "cc" field in the web form, according to fiddler:
In javascript, simply do this:
var data = {
"body": "test message",
"group_id": XXXXXX,
"cc": "[[user:XXXXXX]],[[user:XXXXXX]]",
};
This approach is not documented in Yammer's API so I'm not sure if it will be supported in the future. In the meanwhile, I really wish that Yammer had better documentation. It would save developers lots of time and trouble.

Related

How do I decode/decrypt Apple Server-to-Server Notifications?

My website supports Sign In with Apple.
In the configurations of this service, I have an endpoint here:
What I receive in this endpoint is a JSON like this:
"{"payload":"eyJraW...................NLnyA"}
However, I don't find absolutely anywhere how to decrypt/decode this payload...
The "Learn more" link sends me here: https://developer.apple.com/help/account/configure-app-capabilities/about-sign-in-with-apple
The page below this one is this: https://developer.apple.com/help/account/configure-app-capabilities/enabling-server-to-server-notifications
Nowhere I see how to interpret these messages...
Does anyone know what do I need to do to read these payloads?
It looks like the general procedure for Server-to-Server notifications are outlined here. This is what the docs have to say:
These notifications contain a cryptographically signed payload, in JSON Web Signature (JWS) format, signed by Apple’s private key. After your server receives a notification, examine the JWS payload and use the algorithm specified in the header’s alg parameter to validate the signature. For more information, see Fetch Apple’s public key for verifying token signature.
So, this payload is really just a JWT (verify/decode with the JWT library of your choice, there are many to choose from). Because anyone can access your endpoint, you need to verify that the token is really from Apple. Note: do not try to decode the JWT yourself. Because of security concerns, it is better to let a library do it for you.
After validating the token signature, your server performs work according to the type value in the events claim of the token. The notification payload object contains information about user-initiated account modification events.
The decoded JWT will contain something like this (example is from the docs):
{
"iss": "https://appleid.apple.com",
"aud": "com.mytest.app",
"iat": 1508184845,
"jti": "abede...67890",
"events": {
"type": "email-enabled",
"sub": "820417.faa325acbc78e1be1668ba852d492d8a.0219",
"email": "ep9ks2tnph#privaterelay.appleid.com",
"is_private_email": "true"
"event_time": 1508184845
}
}
events.type has the event that happened (full list is here), and the rest of the token contains everything else you'll need.
#Michael M.'s answer helped me understanding that this payload is basically a JWT.
This is what we need to do (minimal example):
use Firebase\JWT\JWK;
use Firebase\JWT\JWT;
$json = json_decode(file_get_contents('php://input'));
$publicKeys = json_decode(file_get_contents('https://appleid.apple.com/auth/keys'), true);
$decodedPayload = JWT::decode($json->payload, JWK::parseKeySet($publicKeys));
var_dump($decodedPayload);

How to return simple html response with MessagingExtensionActionResponse for a Teams Bot

protected override Task<MessagingExtensionActionResponse> OnTeamsMessagingExtensionSubmitActionAsync(
ITurnContext<IInvokeActivity> turnContext, MessagingExtensionAction action, CancellationToken cancellationToken)
{
return Task.FromResult(new MessagingExtensionActionResponse
{
ComposeExtension = new MessagingExtensionResult
{
Type = "message",
Text ="<div><pre>Hello</pre></div>"
}
});
}
I dont want a hero card that takes up space, just simple plain HTML response like the example above, but i dont know how to do it. The above example dont work.
Currently OnTeamsMessagingExtensionSubmitActionAsync method does not support html response .It has the following options for responding.
No response - You can choose to use the submit action to trigger a
process in an external system, and not provide any feedback to the
user. This can be useful for long-running processes, and you may
choose to provide feedback in another manner (for example, with a
proactive message.
Another task module - You can respond with an
additional task module as part of a multi-step interaction.
Card response - You can respond with a card that the user can then interact
with and/or insert into a message.
Adaptive Card from bot - Insert an Adaptive Card directly into the conversation.
Request the user authenticate
Request the user provide additional configuration
Doc Link
Short and sweet response: MS Bot does not support HTML, use MarkDown instead => https://learn.microsoft.com/en-us/azure/cognitive-services/qnamaker/reference-markdown-format. However, not all the HTML element are available, below an example with hyperlink.
turnContext.SendActivity("[LINK TITLE](URL)");

Get stringified object instead of string with text in when Clicked on Quick reply in FB Messenger Channel (BotFramework v3, Nodejs)

Today, my bot stopped responding to me when clicking on quick replies in FB Messenger. Instead of getting the payload as a string, it now returns a stringified object with extra fields.
I'm using a bot with a custom dynamic dialog and creating SuggestedAction like this:
choices.push(builder.CardAction.postBack(session, "title=Name&params=Some", "Quick Reply Name"));
I used to receive the payload as a string "title=Name&params=Some" in Session object like the following:
session.message.text
But now, in session.message.text, I receive the following string:
"{\r\n \"type\": \"postBack\",\r\n \"value\": \"title=Name&params=Some\"\r\n}"
Has anybody else faced this same issue?
Is this coming from changes in Azure Bot Service? And if so, where can we follow the change log or release notes?
Since card action behavior is channel-specific it's much more likely that this relates to a change in the Facebook Messenger platform. You can view their changelog here: https://developers.facebook.com/docs/messenger-platform/changelog/
I can see there was a change on January 8th. It doesn't mention anything about postBack behavior, but it's still possible that there could be some unintended or undocumented changes that are responsible for the results you're seeing.
It looks like it should be a simple matter to deserialize the JSON and extract the value.
var payload = JSON.parse(session.message.text).value;

beaconinfo.getforobserved always returning an empty response

Here is my request.
POST https://proximitybeacon.googleapis.com/v1beta1/beaconinfo:getforobserved?key=<API_KEY>
with POST data
{
"observations": [
{
"advertisedId": {
"type": "EDDYSTONE",
"id": "XcM0h/AuR31AWAEXxV59Xw=="
},
"timestampMs": "2017-11-28T12:11:23.045123456Z"
}
],
"namespacedTypes": [
"*"
]
}
I've checked the beacon dashboard to see if the beacon has any attachments to it. It has a nearby notification attachment which I want to fetch using this method.
The beaconID in hex is 5dc33487f02e477d40580117c55e7d5f.
I referred to this guide for help but it seems the request they are making is wrong considering the namespacedTypes should be an array and it is a string in the blog.
Here is the documentation for the API.
UPDATE:
If I do a Proximity API list attachment call I get the following result for the same beacon
[
{
"data":"eyJ1cmwiOiAiaHR0cHM6Ly9xLmVkZHkucHJvLzhsMkl3SiIsICJkZXNjcmlwdGlvbiI6ICJTb21lIiwgInRpdGxlIjogIlNvbWUifQ==",
"creationTimeMs":"2017-12-01T18:15:37.418Z",
"attachmentName":"beacons/3!5dc33487f02e477d40580117c55e7d5f/attachments/58dad403-7a99-4085-b338-5fe0b6660abd",
"namespacedType":"com.google.nearby/en"
}
]
Does this mean there is something wrong with the beaconinfo:getforobserved API call?
My understanding is that getforobserved cannot fetch nearby notification attachments but only the attachments defined under the "Attachments" sections in Beacon Dashboard (consisting of a namespace, type and value). The documentation says that getforobserved accepts * to specify all types in all namespaces owned by the client. For nearby notification attachments the namespace is com.google.nearby which is not owned by client. This is my best understanding but I'm not 100% sure about it.
In any case, your getforobserved request looks correct to me. You can verify that the request works correctly by either:
1) Removing the "namespacedTypes" completely from the POST data. In this case the request will not return any attachments but it should return beacon info, so you should get a non-empty answer if the request is otherwise OK.
2) Add an attachment (the other type instead of nearby notification) to the beacon and see if the request returns something. The API will return empty if namespacedTypes is defined but there are no attachments.
Android devices can get nearby notifications automatically if they are enabled on the phone, so typically there should not be need to request the nearby attachments manually. If you want to maintain nearby notification attachments through the API, you can use the other methods provided in the API (such as the list method). If you want to scan for beacons and fetch attachments, I would use the normal attachments which offers more flexibility with the content.

Where do I find the workflow id of an automation in Mailchimp?

I would like to use Mailchimp Api 3.0 to add a subscriber to an automation workflow, but I can't find where the workflow_id or workflow_email_id are located... this is from the documentation:
POST /automations/{workflow_id}/emails/{workflow_email_id}/queue Add a subscriber to a workflow email
http://developer.mailchimp.com/documentation/mailchimp/reference/automations/emails/queue/
Can anyone tell me to find it? It's probably somewhere really obvious. I mean the list_id is well covered, but I can't find any info about this.
I found this confusing as well. Here is how I got the answer:
Send a GET request to https://us9.api.mailchimp.com/3.0/automations to find the workflow_id
With the workflow_id, send a GET request to https://us9.api.mailchimp.com/3.0/automations/<workflow_id>/emails to find the workflow_email_id. The workflow_email_id will be the "id" in the array that's returned.
From there you can make POST requests to https://us9.api.mailchimp.com/3.0/automations/<workflow_id>/emails/<workflow_email_id>/queue
Keep in mind you might need to subscribe an email address to a list first for the post request to work. To subscribe you can use: https://us9.api.mailchimp.com/3.0/lists/<list_id> with your data:
{
"members": [{
"email_address" : "emailaddress#whatever.com",
"status": "subscribed"
}]
}
The answer is found in the official mailchimp knowledge base: It explains that you simply go into the workflow and read the id from the URL.
Other ways to get id information about anything:
Using the API endpoint, detailed here: http://developer.mailchimp.com/documentation/mailchimp/reference/automations/
You'll see that the Response body parameters return everything about the automations, including the id.
Probably the easier way: use the developer playground https://us1.api.mailchimp.com/playground/?_ga=1.218336095.774374564.1480036371
So, once you set up your lists and automations, go into the playground, and you'll find all the ids you'll need for everything.

Resources