Send and Receive Text Messages

Overview

This guide covers sending and receiving messages within a conversation.

Before you begin, make sure you added the SDK to your app and you are able to create a conversation.

NOTE: A step-by-step tutorial to build a chat application is available here.

This guide will make use of the following concepts:

  • Conversation Events - message events that fire on a Conversation, after you are a Member

Send a Text Message

Given a conversation you are already a member of:

conversation.sendMessage({
    "message_type": "text",
    "text": "Hi Vonage!"
}).then((event) => {
    console.log("message was sent", event);
}).catch((error)=>{
    console.error("error sending the message ", error);
});

Receive a Text Message

A message conversation event will be received when a member sends a text message to a conversation:

conversation.on('message', (sender, event) => {
    console.log('*** Message received', sender, event) 
});

Reference