# Messages Resource

Send a message to an Assistant

## Message Properties

<OperationTable type="properties" data={{"type":"object","required":["status","session_id","account_sid"],"refName":"assistants.v1.service.assistant_send_message_response","modelName":"assistants_v1_service_assistant_send_message_response","properties":{"status":{"type":"string","description":"success or failure based on whether the request successfully generated a response."},"flagged":{"type":"boolean","description":"If successful, this property will denote whether the response was flagged or not."},"aborted":{"type":"boolean","description":"This property will denote whether the request was aborted or not."},"session_id":{"type":"string","description":"The unique name for the session."},"account_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^AC[0-9a-fA-F]{32}$","description":"The SID of the [Account](/docs/iam/api/account) that sent the Message."},"body":{"type":"string","description":"If successful, the body of the generated response"},"error":{"type":"string","description":"The error message if generation was not successful"}}}} />

## Send a message to the Assistant

`POST https://assistants.twilio.com/v1/Assistants/{id}/Messages`

### Path parameters

```json
[{"name":"id","in":"path","description":"the Assistant ID.","schema":{"type":"string"},"required":true}]
```

### Request body parameters

```json
{"schema":{"type":"object","required":["identity","body"],"refName":"assistants.v1.service.assistant_send_message_request","modelName":"assistants_v1_service_assistant_send_message_request","properties":{"identity":{"type":"string","description":"The unique identity of user for the session."},"session_id":{"type":"string","description":"The unique name for the session."},"body":{"type":"string","description":"The query to ask the assistant."},"webhook":{"type":"string","description":"The webhook url to call after the assistant has generated a response or report an error."},"mode":{"type":"string","default":"chat","description":"one of the modes 'chat', 'email' or 'voice'"}}},"encodingType":"application/json","conditionalParameterMap":{}}
```

Send a message to the Assistant

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function createMessage() {
  const message = await client.assistants.v1
    .assistants("aia_asst_00000000-1111-2222-3333-444444444444")
    .messages.create({
      identity: "email:test@api.com",
      body: "When was Twilio founded?",
    });

  console.log(message.status);
}

createMessage();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client
from twilio.rest.assistants.v1.assistant import MessageList

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

message = client.assistants.v1.assistants(
    "aia_asst_00000000-1111-2222-3333-444444444444"
).messages.create(
    assistants_v1_service_assistant_send_message_request=MessageList.AssistantsV1ServiceAssistantSendMessageRequest(
        {"identity": "email:test@api.com", "body": "When was Twilio founded?"}
    )
)

print(message.status)
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Assistants.V1.Assistant;
using System.Threading.Tasks;
using System.Collections.Generic;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var message = await MessageResource.CreateAsync(
            assistantsV1ServiceAssistantSendMessageRequest: new MessageResource
                .AssistantsV1ServiceAssistantSendMessageRequest.Builder()
                .WithIdentity("email:test@api.com")
                .WithBody("When was Twilio founded?")
                .Build(),
            pathId: "aia_asst_00000000-1111-2222-3333-444444444444");

        Console.WriteLine(message.Status);
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import java.util.HashMap;
import com.twilio.Twilio;
import com.twilio.rest.assistants.v1.assistant.Message;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

        Message.AssistantsV1ServiceAssistantSendMessageRequest assistantsV1ServiceAssistantSendMessageRequest =
            new Message.AssistantsV1ServiceAssistantSendMessageRequest();
        assistantsV1ServiceAssistantSendMessageRequest.setIdentity("email:test@api.com");
        assistantsV1ServiceAssistantSendMessageRequest.setBody("When was Twilio founded?");

        Message message = Message
                              .creator("aia_asst_00000000-1111-2222-3333-444444444444",
                                  assistantsV1ServiceAssistantSendMessageRequest)
                              .create();

        System.out.println(message.getStatus());
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	assistants "github.com/twilio/twilio-go/rest/assistants/v1"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	params := &assistants.CreateMessageParams{}
	params.SetAssistantsV1ServiceAssistantSendMessageRequest(assistants.assistants_v1_service_assistant_send_message_request{
		Identity: "email:test@api.com",
		Body:     "When was Twilio founded?",
	})

	resp, err := client.AssistantsV1.CreateMessage("aia_asst_00000000-1111-2222-3333-444444444444",
		params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		fmt.Println(resp.Status)
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;
use Twilio\Rest\Assistants\V1\Assistant\MessageModels;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$message = $twilio->assistants->v1
    ->assistants("aia_asst_00000000-1111-2222-3333-444444444444")
    ->messages->create(
        MessageModels::createAssistantsV1ServiceAssistantSendMessageRequest([
            "identity" => "email:test@api.com",
            "body" => "When was Twilio founded?",
        ])
    );

print $message->status;
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

message = @client
          .assistants
          .v1
          .assistants('aia_asst_00000000-1111-2222-3333-444444444444')
          .messages
          .create(
            assistants_v1_service_assistant_send_message_request: {
              'identity' => 'email:test@api.com',
              'body' => 'When was Twilio founded?'
            }
          )

puts message.status
```

```bash
# This endpoint is not currently supported by the Twilio CLI. You can open an issue to request it on https://github.com/twilio/twilio-cli/issues
  # For an alternative low-code solution, check out https://www.twilio.com/docs/openapi/using-twilio-postman-collections
```

```bash
ASSISTANTS_V1_SERVICE_ASSISTANT_SEND_MESSAGE_REQUEST_OBJ=$(cat << EOF
{
  "identity": "email:test@api.com",
  "body": "When was Twilio founded?"
}
EOF
)
curl -X POST "https://assistants.twilio.com/v1/Assistants/aia_asst_00000000-1111-2222-3333-444444444444/Messages" \
--json "$ASSISTANTS_V1_SERVICE_ASSISTANT_SEND_MESSAGE_REQUEST_OBJ" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "aborted": false,
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "body": "When was Twilio founded?",
  "error": "error",
  "flagged": false,
  "session_id": "session_id",
  "status": "status"
}
```
