onMount(async () => {
Talk.ready.then(function () {
const session = new Talk.Session({
appId: '<APP_ID>',
userId: 'nina',
});
session.currentUser.createIfNotExists({
name: 'Nina',
email: 'nina@example.com',
photoUrl: 'https://talkjs.com/new-web/avatar-7.jpg',
welcomeMessage: 'Hi!',
});
const conversationRef = session.conversation('new_conversation');
conversationRef.createIfNotExists();
const chatbox = session.createChatbox();
chatbox.select(conversationRef);
chatbox.mount(document.getElementById('talkjs-container'));
});
});
<script>
let element;
onMount(async () => {
Talk.ready.then(() => {
// Synchronize user data and set up
const me = new Talk.User(oliver);
const other = new Talk.User(abby);
const session = new Talk.Session({ appId, me });
const conversationId = Talk.oneOnOneId(me, other);
const conversation = session.getOrCreateConversation(conversationId);
conversation.setParticipant(me);
conversation.setParticipant(other);
const chatbox = session.createChatbox();
chatbox.select(conversation);
chatbox.mount(element);
});
});
</script>
Because implementing TalkJS was as fast and easy as it was, we were able to greenlight and move this project along very quickly. Had we not chosen this path, the feature would have either been delayed, or shelved due to the resources needed to implement it.