import { useCallback } from "react";
import Talk from "talkjs";
import { Session, Chatbox } from "@talkjs/react";
function ChatComponent() {
const syncUser = useCallback(
() =>
return new Talk.User({
id: "nina",
name: "Nina",
email: "nina@example.com",
photoUrl: "https://talkjs.com/new-web/avatar-7.jpg",
welcomeMessage: "Hi!",
role: "default",
}),
[],
);
const syncConversation = useCallback((session) => {
// JavaScript SDK code here
const conversation = session.getOrCreateConversation("welcome");
const other = new Talk.User({
id: "frank",
name: "Frank",
email: "frank@example.com",
photoUrl: "https://talkjs.com/new-web/avatar-8.jpg",
welcomeMessage: "Hey, how can I help?",
role: "default",
});
conversation.setParticipant(session.me);
conversation.setParticipant(other);
return conversation;
}, []);
return (
<Session appId="<APP_ID>" syncUser={syncUser}>
<Chatbox
syncConversation={syncConversation}
style={{ width: "100%", height: "500px" }}
></Chatbox>
</Session>
);
}
export default ChatComponent;
import { Session, Chatbox } from "@talkjs/react";
<Session appId="t824ba8" userId="pete">
<Chatbox conversation="workshop" className="chatbox"/>
</Session>