Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing provided and formatter function #3

Open
acasolla opened this issue Jun 11, 2020 · 2 comments
Open

missing provided and formatter function #3

acasolla opened this issue Jun 11, 2020 · 2 comments
Assignees

Comments

@acasolla
Copy link

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
Copy link

dalda95 commented Jun 25, 2020

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants