Manually trigger navigation to all chat page and also to single user chat page

Hello, how can I manually trigger navigation to user chat?

I have a custom list of users rendered in users page, I want to attach a chat button that triggers navigation to that user chat page, similar to what this Chat button in screenshot does
image

I have tried attaching this callback to the button,

customChatButton.addEventListener('click', () => {
    window.Discourse.router.transitionTo(`/chat/c/${username}`)
});

but it sends me to “page does not exist or is private”

Also, in that table of users, I have a custom all chat button, and I want when user clicks it it takes them to all chat page, in full screen, not trigger the chat popup from bottom right corner of my screen.

This command does not seem to work:

goToAllChatButton.addEventListener('click', () => {
    window.Discourse.router.transitionTo(`/chat`)
});

You can use this component directly:

<Chat::DirectMessageButton @user={{user}} @modal={{true}} />
3 Likes

Thanks for the reply @joffreyjaffeux, is it possible to do it with the router object directly?