1

I'm using the react native sdk for SFMC and I have some difficulties with getting the inbox messages from the Android platform. Somehow the date format is like: Fri Sep 30 11:16:00 GMT+02:00 2022

And I can't get that formatted to a date object as the year is at the end. I could work around this, but is this the expected format or am I doing something wrong here?

When I do the same thing through iOS, I get the format 2022-10-11T09:53:00+02:00 which is working fine.

Update as an answer to Bill Mote: There's a bridge created in Android to get the messages in RN. When I directly log the messages there:

List<InboxMessage> messages = MarketingCloudSdk.getInstance().getInboxMessageManager().getMessages();
Log.i("aaaaaaa", String.valueOf(messages));

I get this output:

InboxMessage(id=MjMzOjExNDowOnhVN3pqay04cVUyVllORnZxelJ6Q3c, requestId=8ef34ec5-bc4f-4da9-9560-d16fab34730b, messageHash=U4lzMwif3Db1PYIJNML8RQAAAAAA, subject= Inboxing Nico, title=null, alert=null, sound=null, media=null, startDateUtc=Mon Aug 22 15:22:00 GMT+02:00 2022, endDateUtc=Tue Aug 22 15:22:00 GMT+02:00 2023, sendDateUtc=Fri Sep 30 11:16:00 GMT+02:00 2022, url=[some url], custom=null, customKeys=null, viewCount=0), InboxMessage(id=MjMzOjExNDowOjVjVGNsVl9EdzBhZWhwcU5mY1JFeEE, requestId=95dcc4e5-c35f-46c3-9e86-9a8d7dc444c4, messageHash=U4lzMwif3Db1PYIJNML8RQAAAAAA, subject= Inboxing Nico, title=null, alert=null, sound=null, media=null, startDateUtc=Mon Aug 22 15:22:00 GMT+02:00 2022, endDateUtc=Tue Aug 22 15:22:00 GMT+02:00 2023, sendDateUtc=Fri Sep 30 11:16:00 GMT+02:00 2022, url=[url], custom=null, customKeys=null, viewCount=0)

update: Added bridge

@ReactMethod
public void getMessages(Promise promise) {
    try {
        if (!MarketingCloudSdk.isReady()) {
            promise.resolve(Arguments.createArray());
        } else {
            List<InboxMessage> messages = MarketingCloudSdk.getInstance().getInboxMessageManager().getMessages();
            Log.i("messages", String.valueOf(messages));
            WritableArray messageList = SFMCDataManager.processMessageDataList(messages);
            promise.resolve(messageList);
        }
    } catch (Exception e) {
        promise.reject(e);
    }
}

1 Answer 1

0

The React Native plugin does not provide hooks for Inbox Messages, and {bad response removed}:

UPDATE:

You can format the date as needed in your bridge code. For example:

// snipped from a toJson() function for `InboxMessage`
if (startDateUtc != null) put("startDateUtc", startDateUtc.asDateString())

Where asDateString() is an extension function like this:

fun Date.asDateString(): String {
  return SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US).apply {
    timeZone = TimeZone.getTimeZone("UTC")
  }.format(this)
}
11
  • I'll add some more info in my post. Unfortunately this is not my own written code. Where could those modifications be made? Commented Oct 11, 2022 at 14:41
  • Ask the person that wrote your bridge. getMessages is not part of the supported bridge.
    – Bill Mote
    Commented Oct 11, 2022 at 14:59
  • If that person was an option, I wouldn't be here... List<InboxMessage> messages = MarketingCloudSdk.getInstance().getInboxMessageManager().getMessages(); Log.i("aaaaaaa", String.valueOf(messages)); This is in the bridge and gives me the same strange date format. Thanks a lot for the help. Commented Oct 12, 2022 at 6:58
  • 1
    Thanks a freaking lot for pointing me into the solution! I've been spending way to much time on this. Although I still don't understand why the format is not returning correctly in my situation, this finally makes our inbox messages working like it should. Would it be nice to make a PR for the repo as well to get inbox and in-app messages? Commented Oct 13, 2022 at 8:17
  • 1
    Just to add to the discussion. I haven't looked at iOS as that was working OK, but looking at it now it seems there we have the same 'strange' format, but that was already formatted like your suggestion by the developer who wrote this in the first place. Commented Oct 13, 2022 at 10:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .