JavaScript
Send a Message
To send a message to other participants in the Conversation, you need to call the client.sendMessageTextEvent() method.
You can do this by adding a handler for the message box's Submit button at the end of the run function:
// Listen for clicks on the submit button and send the existing text value
sendButton.addEventListener("click", () => {
client
.sendMessageTextEvent(CONVERSATION_ID, messageTextarea.value)
.then((timestamp) => {
console.log("Successfully sent text message at ", timestamp);
messageTextarea.value = "";
})
.catch((error) => {
console.error("Error sending text message: ", error);
});
});
Creating a web-based chat app
Create a web application that enables users to message each other
手順
1
Introduction to this task2
Prerequisites3
Create a Vonage Application4
Create a conversation5
Create the users6
Add users to the conversation7
Generate JWTs8
Install Client SDK9
Create the UI10
Authenticate your Users11
Instantiate VonageClient and create a Session12
Show the message history13
Send a message14
Run your application15
What's next?