Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fern/products/platform/pages/messaging/chat/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ You can create channels, members can subscribe to those channels, and they can s
</Accordion>

<Accordion title="Does Chat support sending/receiving via SMS?">
While Chat does not support sending/receiving via SMS by default, using Relay Realtime SDK along with our [Messaging API](/docs/platform/messaging) you can add SMS support (or any other format of communication) to it!
Chat doesn't send or receive SMS by default, but you can add SMS support (or any other channel) by pairing it with [Messaging](/docs/platform/messaging) through the [Server SDKs](/docs/server-sdks).
</Accordion>

<Accordion title="Can Chat messages be logged?">
Expand Down
296 changes: 229 additions & 67 deletions fern/products/platform/pages/messaging/sms/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ and get registration right the first time with our comprehensive

## Try it out

Replace `<YOUR_SPACE>`, `<YOUR_PROJECT_ID>`, and `<YOUR_API_TOKEN>` in the samples with your Space name, Project ID, and API token, which you'll find in [API credentials](/docs/platform/your-signalwire-api-space).

<AccordionGroup>
<Accordion title="Send an SMS message">
<Tabs>
Expand All @@ -27,35 +29,78 @@ version: 1.0.0
sections:
main:
- send_sms:
from_number: "+155512312345"
from_number: "+15551231234"
to_number: "+15555554321"
body: "Hello from SignalWire!"
```
</Tab>
<Tab title="Relay Realtime SDK (Server)">
```js
import { SignalWire } from "@signalwire/realtime-api";

const client = await SignalWire({ project: "ProjectID Here", token: "Token Here"})

let messageClient = client.messaging;

const sendResult = await messageClient.send({
from: "+155512312345",
to: "+15555554321",
body: "Hello from SignalWire!"
<Tab title="WebSocket (Relay)">
<CodeBlocks>
<CodeBlock title="Python — Relay client">
```python
# Install: python -m pip install signalwire-sdk==3.4.1
# Save as send_sms.py and run: python send_sms.py
import asyncio
from signalwire.relay import RelayClient

client = RelayClient(
project="<YOUR_PROJECT_ID>",
token="<YOUR_API_TOKEN>",
contexts=["default"],
)

async def main():
async with client:
message = await client.send_message(
from_number="+15551231234",
to_number="+15555554321",
body="Hello from SignalWire!",
)
await message.wait(timeout=60)
print(f"Final state: {message.state}")

asyncio.run(main())
```
</CodeBlock>
<CodeBlock title="TypeScript — Relay client">
```typescript
// Install: npm install @signalwire/sdk@2.0.5
// This sample also runs as JavaScript: save as send-sms.mjs,
// then run: node send-sms.mjs
import { RelayClient } from "@signalwire/sdk";

const client = new RelayClient({
project: "<YOUR_PROJECT_ID>",
token: "<YOUR_API_TOKEN>",
contexts: ["default"],
});

await client.connect();

try {
const message = await client.sendMessage({
fromNumber: "+15551231234",
toNumber: "+15555554321",
body: "Hello from SignalWire!",
});
await message.wait(60);
console.log(`Final state: ${message.state}`);
} finally {
await client.disconnect();
}
```
</CodeBlock>
</CodeBlocks>
</Tab>
<Tab title="REST API">
```bash
curl -L 'https://<YOUR_SPACE>.signalwire.com/api/messaging/messages' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Basic <BASE64 ENCODED AUTHENTICATION STRING>' \
-u '<YOUR_PROJECT_ID>:<YOUR_API_TOKEN>' \
-d '{
"to": "+155512312345",
"from": "+15555554321",
"from": "+15551231234",
"to": "+15555554321",
"body": "Hello from SignalWire!"
}'
```
Expand All @@ -71,35 +116,78 @@ version: 1.0.0
sections:
main:
- send_sms:
from_number: "+155512312345"
from_number: "+15551231234"
to_number: "+15555554321"
media: ["https://mcdn.signalwire.com/images/v2/loud/LogoLarge.jpg"]
```
</Tab>
<Tab title="Relay Realtime SDK (Server)">
```js
import { SignalWire } from "@signalwire/realtime-api";

const client = await SignalWire({ project: "ProjectID Here", token: "Token Here"})

let messageClient = client.messaging;

const sendResult = await messageClient.send({
from: "+155512312345",
to: "+15555554321",
media: ["https://mcdn.signalwire.com/images/v2/loud/LogoLarge.jpg"]
<Tab title="WebSocket (Relay)">
<CodeBlocks>
<CodeBlock title="Python — Relay client">
```python
# Install: python -m pip install signalwire-sdk==3.4.1
# Save as send_mms.py and run: python send_mms.py
import asyncio
from signalwire.relay import RelayClient

client = RelayClient(
project="<YOUR_PROJECT_ID>",
token="<YOUR_API_TOKEN>",
contexts=["default"],
)

async def main():
async with client:
message = await client.send_message(
from_number="+15551231234",
to_number="+15555554321",
media=["https://mcdn.signalwire.com/images/v2/loud/LogoLarge.jpg"],
)
await message.wait(timeout=60)
print(f"Final state: {message.state}")

asyncio.run(main())
```
</CodeBlock>
<CodeBlock title="TypeScript — Relay client">
```typescript
// Install: npm install @signalwire/sdk@2.0.5
// This sample also runs as JavaScript: save as send-mms.mjs,
// then run: node send-mms.mjs
import { RelayClient } from "@signalwire/sdk";

const client = new RelayClient({
project: "<YOUR_PROJECT_ID>",
token: "<YOUR_API_TOKEN>",
contexts: ["default"],
});

await client.connect();

try {
const message = await client.sendMessage({
fromNumber: "+15551231234",
toNumber: "+15555554321",
media: ["https://mcdn.signalwire.com/images/v2/loud/LogoLarge.jpg"],
});
await message.wait(60);
console.log(`Final state: ${message.state}`);
} finally {
await client.disconnect();
}
```
</CodeBlock>
</CodeBlocks>
</Tab>
<Tab title="REST API">
```bash
curl -L 'https://<YOUR_SPACE>.signalwire.com/api/messaging/messages' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Basic <BASE64 ENCODED AUTHENTICATION STRING>' \
-u '<YOUR_PROJECT_ID>:<YOUR_API_TOKEN>' \
-d '{
"to": "+155512312345",
"from": "+15555554321",
"from": "+15551231234",
"to": "+15555554321",
"media": ["https://mcdn.signalwire.com/images/v2/loud/LogoLarge.jpg"]
}'
```
Expand All @@ -118,23 +206,59 @@ sections:
body: "The message %{message.body} has been received!"
```
</Tab>
<Tab title="Relay Realtime SDK (Server)">
```js
import { SignalWire } from "@signalwire/realtime-api";

const client = await SignalWire({ project: "ProjectID Here", token: "Token Here"})

await client.messaging.listen({
topics: ["office"],
async onMessageReceived(message) {
client.messaging.send({
to: message.from,
from: message.to,
body: `The message ${message.body} has been received!`
})
}
})
<Tab title="WebSocket (Relay)">

The handler receives texts sent to any number whose **Inbound Message Settings** point at a [Relay Application](/docs/platform/glossary#relay-application) with the topic `office`.

<CodeBlocks>
<CodeBlock title="Python — Relay client">
```python
# Install: python -m pip install signalwire-sdk==3.4.1
# Save as reply_sms.py and run: python reply_sms.py
from signalwire.relay import RelayClient

client = RelayClient(
project="<YOUR_PROJECT_ID>",
token="<YOUR_API_TOKEN>",
contexts=["office"],
)

@client.on_message
async def handle_message(message):
await client.send_message(
from_number=message.to_number,
to_number=message.from_number,
body=f"The message {message.body} has been received!",
)

client.run()
```
</CodeBlock>
<CodeBlock title="TypeScript — Relay client">
```typescript
// Install: npm install @signalwire/sdk@2.0.5
// This sample also runs as JavaScript: save as reply-sms.mjs,
// then run: node reply-sms.mjs
import { RelayClient } from "@signalwire/sdk";

const client = new RelayClient({
project: "<YOUR_PROJECT_ID>",
token: "<YOUR_API_TOKEN>",
contexts: ["office"],
});

client.onMessage(async (message) => {
await client.sendMessage({
fromNumber: message.toNumber,
toNumber: message.fromNumber,
body: `The message ${message.body} has been received!`,
});
});

await client.run();
```
</CodeBlock>
</CodeBlocks>
</Tab>
</Tabs>
</Accordion>
Expand All @@ -152,26 +276,64 @@ sections:
body: "You received a message from %{message.from} to SignalWire number %{message.to}. The message was: %{message.body}"
```
</Tab>
<Tab title="Relay Realtime SDK (Server)">
```js
import { SignalWire } from "@signalwire/realtime-api";

const client = await SignalWire({ project: "ProjectID Here", token: "Token Here"})

await client.messaging.listen({
topics: ["office"],
async onMessageReceived(message) {
client.messaging.send({
to: "+1xxxxxxxxxx",
from: message.to,
body: `
You received a message from ${message.from} to SignalWire number ${message.to}.
The message was: ${message.body}
`
})
}
})
<Tab title="WebSocket (Relay)">

The handler receives texts sent to any number whose **Inbound Message Settings** point at a [Relay Application](/docs/platform/glossary#relay-application) with the topic `office`.

<CodeBlocks>
<CodeBlock title="Python — Relay client">
```python
# Install: python -m pip install signalwire-sdk==3.4.1
# Save as forward_sms.py and run: python forward_sms.py
from signalwire.relay import RelayClient

client = RelayClient(
project="<YOUR_PROJECT_ID>",
token="<YOUR_API_TOKEN>",
contexts=["office"],
)

@client.on_message
async def handle_message(message):
await client.send_message(
from_number=message.to_number,
to_number="+1xxxxxxxxxx",
body=(
f"You received a message from {message.from_number} to SignalWire number "
f"{message.to_number}. The message was: {message.body}"
),
)

client.run()
```
</CodeBlock>
<CodeBlock title="TypeScript — Relay client">
```typescript
// Install: npm install @signalwire/sdk@2.0.5
// This sample also runs as JavaScript: save as forward-sms.mjs,
// then run: node forward-sms.mjs
import { RelayClient } from "@signalwire/sdk";

const client = new RelayClient({
project: "<YOUR_PROJECT_ID>",
token: "<YOUR_API_TOKEN>",
contexts: ["office"],
});

client.onMessage(async (message) => {
await client.sendMessage({
fromNumber: message.toNumber,
toNumber: "+1xxxxxxxxxx",
body:
`You received a message from ${message.fromNumber} to SignalWire number ` +
`${message.toNumber}. The message was: ${message.body}`,
});
});

await client.run();
```
</CodeBlock>
</CodeBlocks>
</Tab>
</Tabs>
</Accordion>
Expand Down
Loading
Loading