Create a Conversation
In this code snippet you learn how to create a Conversation.
Example
Ensure the following variables are set to your required values using any convenient method:
| Key | Description |
|---|---|
CONV_NAME | The unique name of the Conversation. |
CONV_DISPLAY_NAME | The display name of the Conversation. |
Prerequisites
A Vonage application contains the required configuration for your project. You can create an application using the Vonage CLI (see below) or via the dashboard. To learn more about applications see our Vonage concepts guide.
Install the CLI
Create an application
Once you have the CLI installed you can use it to create a Vonage application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step
Vonage needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.
Write the code
Add the following to create-conversation.sh:
curl -X "POST" "https://api.nexmo.com/v1/conversations" \
-H 'Authorization: Bearer '$JWT\
-H 'Content-Type: application/json' \
-d $'{
"name": "$CONV_NAME",
"display_name": "$CONV_DISPLAY_NAME"
}'Run your code
Save this file to your machine and run it:
Prerequisites
A Vonage application contains the required configuration for your project. You can create an application using the Vonage CLI (see below) or via the dashboard. To learn more about applications see our Vonage concepts guide.
Install the CLI
Create an application
Once you have the CLI installed you can use it to create a Vonage application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step
Vonage needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.
npm install @vonage/server-sdkCreate a file named create-conversation.js and add the following code:
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
applicationId: VONAGE_APPLICATION_ID,
privateKey: VONAGE_PRIVATE_KEY,
});Write the code
Add the following to create-conversation.js:
vonage.conversations.createConversation({
'name': CONV_NAME,
'displayName': CONV_DISPLAY_NAME,
})
.then((conversation) => console.log(conversation))
.catch((error) => console.error(error));Run your code
Save this file to your machine and run it:
Prerequisites
A Vonage application contains the required configuration for your project. You can create an application using the Vonage CLI (see below) or via the dashboard. To learn more about applications see our Vonage concepts guide.
Install the CLI
Create an application
Once you have the CLI installed you can use it to create a Vonage application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step
Vonage needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.
Add the following to build.gradle:
implementation 'com.vonage:server-sdk:9.3.1'Create a class named CreateConversation and add the following code to the main method:
VonageClient client = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build();Write the code
Add the following to the main method of the CreateConversation class:
var conversation = client.getConversationsClient().createConversation(
Conversation.builder()
.name(CONV_NAME)
.displayName(CONV_DISPLAY_NAME)
.build()
);
System.out.println(conversation);Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.conversation with the package containing CreateConversation:
Prerequisites
A Vonage application contains the required configuration for your project. You can create an application using the Vonage CLI (see below) or via the dashboard. To learn more about applications see our Vonage concepts guide.
Install the CLI
Create an application
Once you have the CLI installed you can use it to create a Vonage application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step
Vonage needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.
Install-Package VonageCreate a file named CreateConversation.cs and add the following code:
using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Vonage;
using Vonage.Conversations.CreateConversation;
using Vonage.Request;Add the following to CreateConversation.cs:
var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var client = new VonageClient(credentials);Write the code
Add the following to CreateConversation.cs:
var response = await client.ConversationsClient.CreateConversationAsync(CreateConversationRequest.Build()
.WithName(CONV_NAME)
.WithDisplayName(CONV_DISPLAY_NAME)
.Create());Prerequisites
A Vonage application contains the required configuration for your project. You can create an application using the Vonage CLI (see below) or via the dashboard. To learn more about applications see our Vonage concepts guide.
Install the CLI
Create an application
Once you have the CLI installed you can use it to create a Vonage application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step
Vonage needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.
composer require vonage/clientCreate a file named create-conversation.php and add the following code:
use Vonage\Conversation\ConversationObjects\CreateConversationRequest;
require_once __DIR__ . '../../config.php';
require_once __DIR__ . '../../vendor/autoload.php';
$keypair = new \Vonage\Client\Credentials\Keypair(
file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH),
VONAGE_APPLICATION_ID
);
$client = new \Vonage\Client($keypair);Write the code
Add the following to create-conversation.php:
$createConversationRequest = new CreateConversationRequest(CONV_NAME, CONV_DISPLAY_NAME);
$client->conversation()->createConversation($createConversationRequest);Run your code
Save this file to your machine and run it:
Try it out
When you run the code you will create a new Conversation.