Bandyer / Bandyer-Chat-Widget

Bandyer Chat Widget
Other
13 stars 2 forks source link

missing provided and formatter function #3

Open acasolla opened 4 years ago

acasolla commented 4 years ago

The provider and the formatter functions are ignored. Following the initialization code :

` var users = {
"acasolla" : { userAlias: "acasolla", firstName: "Alessandro", lastName: "Casolla", image: "", formattedName : "Alessandro Casolla" }, "guest" : { userAlias: "guest", firstName: "John", lastName: "Doe", image: "", formattedName : "John Doe" } }

function yourFormatterFunction(user){ return user.firstName + " " + user.lastName; }

    function yourProviderFunction(usersAlias){
        const userObjPromises = [];
        usersAlias.forEach( (alias) => {
            const user = users[alias];
            userObjPromises.push(Promise.resolve(user));
        });
        return Promise.all(userObjPromises);
    }

Client = await BandyerChat.create({ userAlias: 'acasolla', appId: 'xxx', environment: 'sandbox', hidden: true, mode : "embed", userDetailsProvider: yourProviderFunction, userDetailsFormatter: yourFormatterFunction });

`

My expectation is that the agent and the customer receives detailed information about the participant, but always get the username.

dalda95 commented 4 years ago

Hi, The Provider and formatter logic work as expected, So I'm going to explain how to tweak your code to make it work as expected.

First of all the provider function, as reported in the DOC,

every single object representing a user and must contain a userAlias key(otherwise the object will be ignored)

always expects to have the userAlias ​​(Bandyer) as the parameter of the return object.

So the change I recommend making is the implementation of a fallback logic in such a way (being the object static and not complete) that you don't risk having an empty user interface.

So try to use the following code, I've tested the behavior and works as expected

const users = {
                "acasolla" : {
                    userAlias: "acasolla",
                    firstName: "Alessandro",
                    lastName: "Casolla",
                    image: "",
                    formattedName : "Alessandro Casolla"
                },
                "guest" : {
                    userAlias: "guest",
                    firstName: "John",
                    lastName: "Doe",
                    image: "",
                    formattedName : "John Doe"
                }
            }

       function yourFormatterFunction(user){
                if(!user.firstName || !user.lastName) {
                    return user.userAlias;
                }
                return user.firstName+ " "+ user.lastName;
            }

       function yourProviderFunction(usersAlias){
                console.log(usersAlias)
                const userObjPromises = [];
                usersAlias.forEach( (alias) => {
                    let user = users[alias];
                    if(!user) {
                        user = {userAlias: alias}
                    }
                    userObjPromises.push(Promise.resolve(user));
                });
                return Promise.all(userObjPromises);

            }

image

acasolla commented 4 years ago

Thx for the reply. I figured out that i was using the providers only on the caller side, and not on the receiver. I added the code to the receiver and now i got correctly the caller information. But i still cannot see the info on the other side :

image I see guest, i was expecting John Doe.