Private message API to give sticky notification

Sigbjørn Vik May 25, 2018

We are using a tool to send automated private messages through the REST API (/v2/user/{id_or_email}/message). It uses a regular account as the sender. Recipients receive messages fine, and a notification popup as expected.

If the recipient already has a conversation open with the sender, then the recipient will also get a sticky message counter on top of that conversation, indicating that there are unread messages. If the recipient does not already have a conversation open, there will be no such notification. In that case, unless the recipient notices the popup, he will not realize there was a message (until he gets the email notification about unread messages). This is unlike manual private messages, which will start a new conversation automatically if one doesn't exist already.

The same happens whether the sender is online or not. Most users use Windows desktop client, but the same behavior also appears on other devices.

What I want to achieve is to send private messages, and have recipients realize they have been messaged. Any clues to how I can achieve this?

5 answers

0 votes
Sigbjørn Vik June 8, 2018

I have now changed the default value for the notify flag to true. As should be expected, this does not change the behavior, as the default value was not being used.

The behavior is still as follows: If the sender is not already visible in the list of people the recipient is talking to, then the sender will not appear in that list, and thus the sticky notifications will not be visible to the recipient. If the sender is already in that list, then sticky notifications will be visible as expected.

AhmadDanial
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 10, 2018

Hi, Sigbjørn. 

That is interesting. I figured that the function will work correctly since notify is set to true already:

public async Task PrivateMessageAsync(String user, String message, bool notify = true, MessageFormat messageFormat = MessageFormat.Html)

 Let us see if others might have another idea on this one.

0 votes
Sigbjørn Vik June 6, 2018

Does that answer your last question?

Anyone else who knows anything about this?

0 votes
Sigbjørn Vik May 29, 2018

That is the default value of the parameter to the function. As you can see from screenshot #2, notifications do work (given that the conversation is already open), showing that the function is called with notify set to true. If I call the API with notify = false instead, then the message counter does not appear on top of the conversation. The function is called from this code:

await tools.PrivateMessageAsync(hipChatId, message, true);

 

AhmadDanial
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 7, 2018

Hello, Sigbjørn.

 

Thank you for the confirmation from your end. Since the notify is an essential parameter to indicate the users that there is a new message as mentioned in the send room notification API V2 page, I would recommend you to have it set to true rather than using the default value of false. As mentioned in the page:

Whether this message should trigger a user notification (change the tab color, play a sound, notify mobile phones, etc). Each recipient's notification preferences are taken into account.

Defaults to false.

Please let me know how it goes on your end. 

0 votes
Sigbjørn Vik May 28, 2018

Yes, the notify flag is set to true. The code used is this:

public async Task PrivateMessageAsync(String user, String message, bool notify = false, MessageFormat messageFormat = MessageFormat.Html)
{
var endpoint = new System.Uri($"https://api.hipchat.com/v2/user/{user}/message");

dynamic jsonRequest = new JObject();
jsonRequest.notify = notify;
jsonRequest.message_format = messageFormat.ToString().ToLower();
jsonRequest.message = message;

using (var request = new WebClient())
{
request.Headers.Add("Authorization", "Bearer " + HipChatConnectionKey);
request.Headers.Add("Content-type", "application/json");
await request.UploadStringTaskAsync(endpoint, jsonRequest.ToString(Formatting.None));
}
}

screenshot.pngAttaching an image, on top what it looks like if the conversation with the sender is not already open, on the bottom what it looks like when it is open. You will notice that in the second case, the sticky message counters will be present.

AhmadDanial
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 29, 2018

Good day, Sigbjørn. 

I noticed that the parameter here is set to false:

bool notify = false

 Can you please confirm if the behavior is the same when you set it to true instead?

0 votes
AhmadDanial
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 27, 2018

Hey, Sigbjørn.

Can I please confirm with you if you have the notify flag set to true?

curl -H "Content-Type: application/json" -X POST -d "{\"message_format\": \"text\", \"notify\": \"true\", \"message\": \"Testing\" }" https://<fqdn>/v2/user/<user_id>/message?auth_token=<api_token>

I had this tested on Mac and Windows client and confirmed that I was still getting the pop up notification and the unread notification will be displayed on the left side of the client using the snippet example above. I'll also be interested to know how you use the API v2 on your end. If you can share an example, that will be great so I can test it on my end.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events