Assistant Sms Chat
Send an SMS message for an assistant. This endpoint:
- Validates the assistant exists and has messaging profile configured
- If should_create_conversation is true, creates a new conversation with metadata
- Sends the SMS message (If
textis set, this will be sent. Otherwise, if this is the first message in the conversation and the assistant has agreetingconfigured, this will be sent. Otherwise the assistant will generate the text to send.) - Updates conversation metadata if provided
- Returns the conversation ID
POST
/
ai
/
assistants
/
{assistant_id}
/
chat
/
sms
JavaScript
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const response = await client.ai.assistants.sendSMS('assistant_id', { from: 'from', to: 'to' });
console.log(response.conversation_id);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
response = client.ai.assistants.send_sms(
assistant_id="assistant_id",
from_="from",
to="to",
)
print(response.conversation_id)package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.AI.Assistants.SendSMS(
context.TODO(),
"assistant_id",
telnyx.AIAssistantSendSMSParams{
From: "from",
To: "to",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.ConversationID)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.ai.assistants.AssistantSendSmsParams;
import com.telnyx.sdk.models.ai.assistants.AssistantSendSmsResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
AssistantSendSmsParams params = AssistantSendSmsParams.builder()
.assistantId("assistant_id")
.from("from")
.to("to")
.build();
AssistantSendSmsResponse response = client.ai().assistants().sendSms(params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
response = telnyx.ai.assistants.send_sms("assistant_id", from: "from", to: "to")
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$response = $client->ai->assistants->sendSMS(
'assistant_id',
from: 'from',
to: 'to',
conversationMetadata: ['foo' => 'string'],
shouldCreateConversation: true,
text: 'text',
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx ai:assistants send-sms \
--api-key 'My API Key' \
--assistant-id assistant_id \
--from from \
--to tocurl --request POST \
--url https://api.telnyx.com/v2/ai/assistants/{assistant_id}/chat/sms \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"from": "<string>",
"to": "<string>",
"text": "<string>",
"conversation_metadata": {},
"should_create_conversation": true
}
'{
"conversation_id": "<string>"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Path Parameters
Unique identifier of the assistant.
Body
application/json
Response
Successful Response
Was this page helpful?
⌘I
JavaScript
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const response = await client.ai.assistants.sendSMS('assistant_id', { from: 'from', to: 'to' });
console.log(response.conversation_id);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
response = client.ai.assistants.send_sms(
assistant_id="assistant_id",
from_="from",
to="to",
)
print(response.conversation_id)package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.AI.Assistants.SendSMS(
context.TODO(),
"assistant_id",
telnyx.AIAssistantSendSMSParams{
From: "from",
To: "to",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.ConversationID)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.ai.assistants.AssistantSendSmsParams;
import com.telnyx.sdk.models.ai.assistants.AssistantSendSmsResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
AssistantSendSmsParams params = AssistantSendSmsParams.builder()
.assistantId("assistant_id")
.from("from")
.to("to")
.build();
AssistantSendSmsResponse response = client.ai().assistants().sendSms(params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
response = telnyx.ai.assistants.send_sms("assistant_id", from: "from", to: "to")
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$response = $client->ai->assistants->sendSMS(
'assistant_id',
from: 'from',
to: 'to',
conversationMetadata: ['foo' => 'string'],
shouldCreateConversation: true,
text: 'text',
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx ai:assistants send-sms \
--api-key 'My API Key' \
--assistant-id assistant_id \
--from from \
--to tocurl --request POST \
--url https://api.telnyx.com/v2/ai/assistants/{assistant_id}/chat/sms \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"from": "<string>",
"to": "<string>",
"text": "<string>",
"conversation_metadata": {},
"should_create_conversation": true
}
'{
"conversation_id": "<string>"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}