0

I am currently trying to use SendBird SDK and have been trying to call this function and getting errors back when I do. Below is there method they give on their documentation.

channel.sendUserMessage(message, data, customType, function(message, error){
    if (error) {
        console.error(error);
        return;
    }

    console.log(message);
});

Here is what I use:

channelList[i].sendUserMessage(message, function (message, error) {

    if (error) {
        console.error(error);
        return;
    }

    console.log(message);
    document.getElementById(url + "ChatInput").value = "";

});

The error I get back is this:

I {name: "SendBirdException", code: 900025, message: "Message is blocked due to invalid type of 'mentioned_user_ids'"}
code: 900025
message: "Message is blocked due to invalid type of 'mentioned_user_ids'"
name: "SendBirdException"

Now I am only uploading a string and was really confused at first where mentioned_users_ids was coming from but I figured out why. I believe in the SendBird SDK they use Typescript and multiple overloads for different paramaters based on this file:

https://github.com/smilefam/SendBird-SDK-JavaScript/blob/master/SendBird.d.ts

and specifically this part in that file:

sendUserMessage(userMessageParams: UserMessageParams, callback: messageCallback): UserMessage;
sendUserMessage(message: string, callback: messageCallback): UserMessage;
sendUserMessage(message: string, data: string, callback: messageCallback): UserMessage; // DEPRECATED
sendUserMessage(message: string, data: string, customType: string, callback: messageCallback): UserMessage; // DEPRECATED
sendUserMessage(
   message: string,
   data: string,
   customType: string,
   targetLanguages: Array<string>,
   callback: messageCallback
): UserMessage;

I believe since I am not using Typescript I believe its defaulting to the first function in that list that uses userMessageParams which consists of:

interface UserMessageParams {
    message: string;
    data: string;
    customType: string;
    targetLanguages: Array<string>;
    mentionType: 'users' | 'channel';
    mentionedUserIds: Array<string>;
    mentionedUsers: Array<User>;
    pushNotificationDeliveryOption: 'default' | 'suppress';
}

Which includes the property that was mentions in the error before as 'mentioned_user_ids'.

My question is if is possible to default it to the simple overload of just the string and callback function:

sendUserMessage(message: string, callback: messageCallback): UserMessage;

instead of:

sendUserMessage(userMessageParams: UserMessageParams, callback: messageCallback): UserMessage;

without using Typescript.

What I tried

I tried to just make the object myself by doing:

var userMessageParams = new sb.UserMessageParams();
userMessageParams.message = message;
userMessageParams.mentionType = "channel";

channelList[i].sendUserMessage(userMessageParams, function (message, error) {
    if (error) {
        console.error(error);
        return;
    }

    console.log(message);
    document.getElementById(url + "ChatInput").value = "";
});

But I still get the same error as mentioned above.

null_data:null
_mentionType:"channel"
_mentionedIds:["d155d9e51f3e4897988e39a8f33c89a6"]
_mentionedUserIds:["d155d9e51f3e4897988e39a8f33c89a6"]
_mentionedUsers:[]
_message:"message"
_pushNotificationDeliveryOption:null
_targetLanguages:null

I manually set the values of the property inside userMessageParams:

userMessageParams.mentionedUserIds = [ channelList[0].members[1].userId, channelList[0].members[0].userId];

_customType:null
_data:null
_mentionType:"channel"
_mentionedIds:["d155d9e51f3e4897988e39a8f33c89a6"]
_mentionedUserIds:["d155d9e51f3e4897988e39a8f33c89a6"]
_mentionedUsers:[]
_message:"message"
_pushNotificationDeliveryOption:null
_targetLanguages:null

//Inside console in Chrome
channelList[0].members[1].userId
"d155d9e51f3e4897988e39a8f33c89a6"

channelList[0].members[0].userId
"1924c64299284da6b8e6366a7f0b7a7c"

(I don't know why it only added one of them inside userIds, I verified both had values in the console before and after adding it. Probably doesn't add values if it's the same as the senderId in the background or that is the best guess I have) And I still get the same errors.

I don't want to mention certain users because this is just used for 1 on 1 chat so I don't really need it.

Solutions

The two possible solutions I see right now are:

  • Figure out of who default to the string overload (I have never used Typescript and don't know how its transcompiled to java-script so I don't know if that's possible).
  • Figure out where I am messing up on making the userMessageParams, and there I don't even want to mention any users.

Sorry for the essay, if anyone has any information that could help out or need more clarification to help me, anything would be greatly appreciated, thanks!

Transcompiled code

...if anyone is crazy enough to look at this, (or what I think it is) located in the SendBird.min.js):

this.sendUserMessage = function(e, n, t, r, i) {
                var a = this
                  , s = le.MentionType.USERS
                  , o = []
                  , l = ue.PushNotificationDeliveryOption.DEFAULT;
                if ("function" == typeof n && (i = n,
                n = "",
                t = "",
                r = [],
                e instanceof ue)) {
                    var u = e;
                    e = u.message,
                    n = u.data,
                    t = u.customType,
                    r = u.targetLanguages,
                    s = u._mentionType,
                    o = u._mentionedIds,
                    l = u.pushNotificationDeliveryOption ? u.pushNotificationDeliveryOption : ue.PushNotificationDeliveryOption.DEFAULT
                }
                if ("function" == typeof t && (i = t,
                t = "",
                r = []),
                "function" == typeof r && (i = r,
                r = []),
                r || (r = []),
                "string" == typeof r && (r = [r]),
                null === n && (n = ""),
                null === t && (t = ""),
                "string" != typeof e || "string" != typeof n || "string" != typeof t || !Array.isArray(r) || [ue.PushNotificationDeliveryOption.DEFAULT, ue.PushNotificationDeliveryOption.SUPPRESS].indexOf(l) < 0)
                    return void U(null, new I("Invalid parameter.",C.INVALID_PARAMETER), i);
                var c = null;
                if (!he.getInstance() || !he.getInstance().currentUser)
                    return i && U(null, new I("Connection should be made first.",C.CONNECTION_REQUIRED), i),
                    c;
                var d = q.bMessage(this.url, e, n, t, s, o, r, l)
                  , h = M.build(d.requestId, 0, he.getInstance().currentUser, this, e, n, t, r, (new Date).getTime(), null, s, null, o);
                return c = new M(h),
                he.getInstance().sendCommand(d, function(e, n) {
                    if (n)
                        return void U(null, new I(n.message,n.code), i);
                    var t = new M(e.getJsonElement())
                      , r = he.getInstance().currentUser;
                    r && t._sender && r.userId === t._sender.userId && (r.nickname !== t._sender.nickname && (r.nickname = t._sender.nickname),
                    r.profileUrl !== t._sender.profileUrl && (r.profileUrl = t._sender.profileUrl)),
                    a.isGroupChannel() && F.getChannel(a.url, function(e, n) {
                        if (R) {
                            var r = e;
                            e = n,
                            n = r
                        }
                        if (n)
                            return void U(null, n, i);
                        e.lastMessage = t;
                        for (var a in he.getInstance().channelHandlers) {
                            he.getInstance().channelHandlers[a].onChannelChanged(e)
                        }
                    }),
                    U(t, null, i)
                }),
                c
            }
molinamos
  • 1
  • 1
  • I tried other versions of SendBird and my code works with version 3.0.54 worked before sendUserParams was added. That is the only thing that has been added to SendBird SDK that would be causing this "bug" maybe. I also used version 3.0.78 and also got the same error. – molinamos Sep 26 '18 at 06:23

1 Answers1

0

SendBird doesn't use TypeScript. The interface file is just written with that. https://github.com/smilefam/SendBird-SDK-JavaScript/blob/master/SendBird.d.ts Inside, it is vanilla JS.

The code that you mentioned above should work without needing to define the UserMessageParam.

    channelList[i].sendUserMessage(message, function (message, error) {

        if (error) {
            console.error(error);
            return;
        }

        console.log(message);
        document.getElementById(url + "ChatInput").value = "";

    });

Please try to debug stepping through. Also, please check sample code that has similar implementation. https://github.com/smilefam/SendBird-JavaScript

Imju
  • 539
  • 5
  • 11
  • In the newer versions of SendBird SDK, past 3.0.54, it kept giving me UserMessageParam error when I put a string in for message. I tried this on 3.0.78 and 3.0.81 I believe and still got the error saying mentioned user id's is invalid. I debugged through to to make sure message had a string value before the sendUserMessage was called. I even hard coded message and still got the same error. – molinamos Sep 28 '18 at 12:29
  • Please check out the sample project, https://github.com/smilefam/SendBird-JavaScript. SendUserMessage without the UserMessageParam is used successfully. – Imju Sep 29 '18 at 15:28
  • The javascript SDK webwidget one is using v3.0.45. I am just saying that in the new v3.0.81 it didn't work. – molinamos Sep 30 '18 at 17:15
  • Are you using the web widget sample? That's when you are seeing this problem? Can you clarify this? The question was about the certain call but if it is a web widget sample having that issue, then it is a different topic. Can you pinpoint to which file of the web widget sample? – Imju Oct 01 '18 at 19:52
  • No, not the web widget sample, I made my own project using the newer versions of the SDK. The web widget sample uses an older SDK and words just fine. I'm seeing the problem when I am using send message on my own project. It works perfectly in older versions of the JS SDK but not the new ones as in the v3.0.81. Everything is working now that I reverted to the older SDK I was just curious on the new versions , v3.0.81, why you still can't just use a string as the message input. – molinamos Oct 03 '18 at 01:01