Record a Conversation

In this code snippet you will see how to record a Conversation.

Example

Ensure the following variables are set to your required values using any convenient method:

Key Description
CONVERSATION_ID Unique ID of the Conversation.

Prerequisites

Use your existing application

You will need to use an existing Application that contains Conversations in order to be able to record one. See the Create Conversation code snippet for information on how to create an Application and some sample Conversations.

Install dependencies

gem install nexmo
Initialize your dependencies

Create a file named record_conversation.rb and add the following code:

Copy to Clipboard
client = Nexmo::Client.new(
  api_key: NEXMO_API_KEY,
  api_secret: NEXMO_API_SECRET,
  application_id: NEXMO_APPLICATION_ID,
  private_key: File.read(NEXMO_APPLICATION_PRIVATE_KEY_PATH)
)

View full source

Write the code

Add the following to record_conversation.rb:

Copy to Clipboard
response = client.conversations.record(CONVERSATION_ID, {
  action: 'start',
  split: 'conversation',
  format: 'mp3'
})

puts response.inspect

View full source

Run your code

Save this file to your machine and run it:

ruby record_conversation.rb

Try it out

When you run the code you will record the specified Conversation.