Get unread message via rest api for Rocket.chat - rocket.chat

I'm trying to get the numbers of direct unread messages in rocket.chat.
I'm on 0.53.0 and trying with /api/v1/im.history to get the numbers of unreads. If I set unreads to "true" I can't distinguish between read and unread.
What is the way to get the numbers of unread?

When calling the /api/v1/im.history if you set unreads to true you should have 3 properties on the object returned:
messages
firstUnread
unreadNotLoaded
This will be the first message unread. You would need to then find all messages with a newer timestamp and that would be your unread messages.
Reference to the code generating this payload: https://github.com/RocketChat/Rocket.Chat/blob/0.53.0/packages/rocketchat-lib/server/methods/getChannelHistory.js#L72

Related

Trying to process a message received in Bytes using google Protobuf, but sometimes getting "Protocol message end-group tag did not match expected tag"

We are processing messages received from a Queue, which is in byte[]. And processing them using google Protobuf-java-2.6.1.jar calling mergeFrom of the com.google.protobuf.AbstractMessage, which in turn is calling com.google.protobuf.CodedInputStream.
Sometimes, the messages are successfully processed, but sometimes throwing InvalidProtocolBufferException.invalidTag().
I understand that "Groups in protobuf are written as a start/end numeric pair", But as we are receiving the messages in byte[], how can we make sure what are the start and end tags and which end group tag not matched with what expected Tag?
Sometimes, the same message get processed successfully on a local windows machine, but the same message fails on a Linux box.
Message.Builder builder = getMessageBuilder(messageType);
ExtensionRegistry registry = ExtensionRegistry.newInstance();
Message parsedMessage = builder.mergeFrom(message, registry).build();`
message is a byte[].
The 3rd line is throwing the exception.

Can't read or count messages on GSM Modem

I am using a Huawei E303 modem and I am not seeing new messages via AT commands. Huawei's application "Mobile Partner" is able to read these messages but I don't understand how.
I have set AT+CMGF=1 and when I try AT+CPMS? I get +CPMS:"SM",0,30,"SM",0,30,"SM",0,30
When a new message arrives I get a +CTMI: "SM", 0 every single time. That value never increments. AT+CMGL="ALL" returns response OK but no messages.
I am now out of ideas. How can I read a message if counting them always returns zero?
What is amazing is that the Huawei application can read incoming messages, can send messages without any problems.

(Kannel) No foreign message ID when sending concatenated messages

I am trying to send multipart (concatenated) messages using Kannel.
Currently, Kannel is configured to call a dlr url (which is a PHP script) that does some stuff with the delivery report.
When sending single message (ie a message that has 10 characters), it does get delivered to my mobile phone and Kannel calls the dlr url twice, both times returning the foreign message ID - both when the dlr status code was 8, which means that it was accepted by SMSC, and when the dlr status code was 1, which means the message was delivered (as it really was).
Now, that works all great but when I try to send a multipart message (ie a message that has 250 characters), it again gets delivered to my phone as one message (as I set the concatenation parameter to true), but when Kannel called that dlr url when status code was 8 (accepted by SMSC) - it didn't provide any foreign message id, as it would normally in the previous example with message of 10 characters.
I could see in the logs that Kannel indeed received two foreign message ID's from the SMSC (ie 123 and 124), but when calling the dlr url on status code 8 (accepted by SMSC) Kannel never provided those IDs so the field in the database I use to store these IDs has been set from NULL to an empty string.
What is really confusing is that once the multi-part message got delivered to my phone, Kannel called that dlr url again with status code of 1 (delivered) and it passed the foreign message id of the first message, which is what I want to be passed on any status code.
So my question is - how can I make Kannel use that foreign message id when calling the dlr url when status code is 8 (accepted by SMSC)? It works when status code is 1 (delivered) but not when status code is 8.
Note: I am using Kannel 1.4.4 but I am willing to upgrade if there's a newer version with this feature included.

Implementing bulk-messaging from Salesforce to/from Twilio, hitting Salesforce API limits

I am building an integration between Salesforce and Twilio that sends/receives SMS using TwilioForce REST API. The main issue is getting around the 10-call API limit from Salesforce, as well as the prohibition on HTTP call outs from a trigger.
I am basing the design on Dan Appleman's Asynchronous Request processes, but in either Batch mode or RequestAsync(), ASync(), Sync(), repeat... I'm still hitting the limits.
I'd like to know how other developers have done this successfully; the integrations have been there for a while, but the examples are few and far between.
Are you sending unique messages for each record that has been updated? If not, then why not send one message to multiple recipients to save on your API limits?
Unfortunately, if you do actually need to send more than 10 unique messages there is no way to send messages in bulk with the Twilio API, you could instead write a simple application that runs on Heroku or some other application platform that you can call out to that will handle the SMS functionality for you.
I have it working now using the following structure (I apologize for the formatting - it's mostly pseudocode):
ASyncRequest object:
AsyncType (picklist: 'SMS to Twilio' is it for now),
Params (long text area: comma-separated list of Ids)
Message object:
To (phone), From (phone), Message (text), Sent (boolean), smsId (string), Error (text)
Message trigger: passes trigger details to CreateAsyncRequests() method.
CreateAsyncRequests: evaluate each new/updated Message__c; if Sent == false for any messages, we create an AsyncRequest, type=SMS to Twilio, Params += ',' + message.Id.
// Create a list to be inserted after all the Messages have been processed
List requests = new List();
Once we reach 5 message.Ids in a single AsyncRequest.Params list, add it to requests.
If all the messages have been processed and there's a request with < 5 Ids in Params, add it to requests as well.
If requests.size() > 0 {
insert requests;
AsyncProcessor.StartBatch();
}
AsyncProcessor implements .Batchable and .AllowsCallouts, and queries ASyncRequest__c for any requests that need to be processed, which in this case will be our Messages list.
The execute() method takes the list of ASyncRequests, splits each Params value into its component Message Ids, and then queries the Message object for those particular Messages.
StartBatch() calls execute() with 1 record at a time, so that each execute() process will still contain fewer than the maximum 10 callouts.
Each Message is processed in a try/catch block that calls SendMessage(), sets Message.smsId = Twilio.smsId and sets Message.Sent = true.
If no smsId is returned, then the message was not sent, and I set a boolean bSidIsNull = true indicating that (at least) one message was not sent.
** If any message failed, no smsIds are returned EVEN FOR MESSAGES THAT WERE SUCCESSFUL **
After each batch of messages is processed, I check bSidIsNull; if true, then I go back over the list of messages and put any that do not have an smsId into a map indexed by the Twilio number I'm trying to send them From.
Since I limited each ASyncRequest to 5 messages, I still have the use of a callout to retrieve all of the messages sent from that Twilio.From number for the current date, using
client.getAccount().getMessages('From' => fromNumber, 'DateSent' => currentDate)
Then I can update the Message.smsIds for all of the messages that were successful, and add an error message to Message.Error_on_Send__c for any that failed.

Selecting an outgoing mail message programmatically

Here's what I'm attempting to do: Let's assume that you are in mail and create a New blank mail message, then enter some data into it, such as body copy, etc. (in my case, the message was created through scripting bridge using the "Mail Contents of this Page" from safari... the main purpose of this process for my application.)
From my application, I want to select that message and assign it to:
MailOutgoingMessage *myMessage;
so that I can programmatically add recipients. I've tried several ways of doing this which seemed logical, but so far I haven't found the right combination, and the header file doesn't seem to be very clear to me (I'm new to scripting bridge.)
My initial thought was to try this:
mailMessage = [[mail outgoingMessages] lastObject];
Which should grab the last outgoing message created. It seems to work in that I am able to add recipients to mailMessage (though there have been a few times that I received unexpected results when multiple outgoing messages exist, such as adding the recipients to the wrong message) but attempting to log the subject line of the message:
NSLog(#"Subject = %#",[mailMessage subject]);
always returns NULL even though there is a subject clearly viewable in the subject field of the message. NULL is returned for any other parameter as well.
I'm gathering it must be a problem with my assignment to mailMessage above, because the only time I receive a NULL for message properties (or receive unexpected results) is if I try to point mailMessage to an existing outgoing message. If I create the mail message with scripting bridge, then I can retrieve all of the properties correctly.
Does anyone understand the hierarchy of the Mail scripting enough to tell me why I am getting NULLs for the parameters using the above assignment for mailMessage? What would the simplest way be go grab my message so that I can add recipients and later call the:
[myMessage send];
method? Any insight would be helpful. I've spent a week going through the mail.h header file and am quite literally at a loss as to what else to try at this point.
There's no way to (send, get or set the properties of the outgoing message) that the user or Safari has created.
It's a bug (it stopped working since Mac OS X 10.4), or some privacy/security considerations.

Resources