diff --git a/fern/products/platform/pages/messaging/chat/overview.mdx b/fern/products/platform/pages/messaging/chat/overview.mdx index 161777bc85..336af8436d 100644 --- a/fern/products/platform/pages/messaging/chat/overview.mdx +++ b/fern/products/platform/pages/messaging/chat/overview.mdx @@ -80,7 +80,7 @@ You can create channels, members can subscribe to those channels, and they can s - 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). diff --git a/fern/products/platform/pages/messaging/sms/overview.mdx b/fern/products/platform/pages/messaging/sms/overview.mdx index 8e4142f2ba..ae8a8479ea 100644 --- a/fern/products/platform/pages/messaging/sms/overview.mdx +++ b/fern/products/platform/pages/messaging/sms/overview.mdx @@ -18,6 +18,8 @@ and get registration right the first time with our comprehensive ## Try it out +Replace ``, ``, and `` 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). + @@ -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!" ``` - -```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!" + + + +```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="", + 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()) +``` + + +```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: "", + 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(); +} ``` + + ```bash curl -L 'https://.signalwire.com/api/messaging/messages' \ -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ - -H 'Authorization: Basic ' \ + -u ':' \ -d '{ - "to": "+155512312345", - "from": "+15555554321", + "from": "+15551231234", + "to": "+15555554321", "body": "Hello from SignalWire!" }' ``` @@ -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"] ``` - -```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"] + + + +```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="", + 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()) +``` + + +```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: "", + 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(); +} ``` + + ```bash curl -L 'https://.signalwire.com/api/messaging/messages' \ -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ - -H 'Authorization: Basic ' \ + -u ':' \ -d '{ - "to": "+155512312345", - "from": "+15555554321", + "from": "+15551231234", + "to": "+15555554321", "media": ["https://mcdn.signalwire.com/images/v2/loud/LogoLarge.jpg"] }' ``` @@ -118,23 +206,59 @@ sections: body: "The message %{message.body} has been received!" ``` - -```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!` - }) - } -}) + + +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`. + + + +```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="", + 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() ``` + + +```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: "", + 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(); +``` + + @@ -152,26 +276,64 @@ sections: body: "You received a message from %{message.from} to SignalWire number %{message.to}. The message was: %{message.body}" ``` - -```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} - ` - }) - } -}) + + +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`. + + + +```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="", + 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() +``` + + +```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: "", + 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(); ``` + + diff --git a/fern/products/platform/pages/platform/setup/api-credentials.mdx b/fern/products/platform/pages/platform/setup/api-credentials.mdx index 2b8dc0caac..3c84cb3c40 100644 --- a/fern/products/platform/pages/platform/setup/api-credentials.mdx +++ b/fern/products/platform/pages/platform/setup/api-credentials.mdx @@ -107,10 +107,50 @@ Find the correct credentials structure for each specific call in the [SDK Refere [REST API Reference](/docs/apis), or in a specific [Guide](/docs/browser-sdk/guides/overview) you may wish to follow. -For a general example, we can look at how to list video rooms with the **REST API**: +For example, list video rooms with the REST client in the [Server SDKs](/docs/server-sdks), or call the **REST API** directly: + + + + +```python +# Install: python -m pip install signalwire-sdk==3.4.1 +from signalwire.rest import RestClient + +client = RestClient( + project="", + token="", + host=".signalwire.com", +) + +rooms = client.video.rooms.list() +for room in rooms.get("data", []): + print(f"{room['name']}: {room['id']}") +``` + + +```typescript +// Install: npm install @signalwire/sdk@2.0.5 +import { RestClient } from "@signalwire/sdk"; + +const client = new RestClient({ + project: "", + token: "", + host: ".signalwire.com", +}); + +const rooms = await client.video.rooms.list(); +for (const room of rooms.data ?? []) { + console.log(`${room.name}: ${room.id}`); +} +``` + + + + + This example uses curl with the `-u` flag to make a request with Basic Auth. @@ -124,16 +164,14 @@ curl https://.signalwire.com/api/video/rooms \ -We use the external dependency -[Axios](https://axios-http.com/) -to make this call, so it must also be imported and installed. +This example uses [Axios](https://axios-http.com/), so install it before you run the script. ```javascript // npm install axios import axios from "axios"; await axios - .get("https://.signalwire.com/api/video/rooms", { + .get("https://.signalwire.com/api/video/rooms", { auth: { username: "", password: "" }, }) .then((response) => { @@ -147,16 +185,3 @@ await axios - -Or with the **Realtime SDK**, you may use these credentials to create a Video Client. - -```javascript -import { Video } from "@signalwire/realtime-api"; - -const video = new Video.Client({ - project: "", - token: "", -}); -``` - -Note that you are not required to pass the Space URL when working with the SDK. diff --git a/fern/products/swml/pages/guides/basics/deployment.mdx b/fern/products/swml/pages/guides/basics/deployment.mdx index c5ba86c661..ddefc9eaaf 100644 --- a/fern/products/swml/pages/guides/basics/deployment.mdx +++ b/fern/products/swml/pages/guides/basics/deployment.mdx @@ -145,10 +145,49 @@ sections: ## From a Relay application You can also execute SWML from a Relay application. -The following is a snippet using the [Relay SDK](/docs/server-sdks/reference/python/relay). +The following handler uses the Relay client in the [Server SDKs](/docs/server-sdks). + + + +```python +# Install: python -m pip install signalwire-sdk==3.4.1 +# Save as swml_relay.py and run: python swml_relay.py +from signalwire.relay import RelayClient + +SCRIPT = """ +version: 1.0.0 +sections: + main: + - answer: {} + - execute: + dest: play_music + params: + to_play: 'https://cdn.signalwire.com/swml/April_Kisses.mp3' + play_music: + - play: + url: '%{params.to_play}' +""" + +client = RelayClient( + project="", + token="", + contexts=["swml"], +) + +@client.on_call +async def handle_call(call): + await call.transfer(SCRIPT) + +client.run() +``` + + +```typescript +// Install: npm install @signalwire/sdk@2.0.5 +// This sample also runs as JavaScript: save as swml-relay.mjs, +// then run: node swml-relay.mjs +import { RelayClient } from "@signalwire/sdk"; -```javascript -const { Voice } = require("@signalwire/realtime-api"); const script = ` version: 1.0.0 sections: @@ -163,29 +202,25 @@ sections: url: '%{params.to_play}' `; -const client = new Voice.Client({ - project: "", - token: "", - topics: ["swml"], +const client = new RelayClient({ + project: "", + token: "", + contexts: ["swml"], }); -client.on("call.received", async (call) => { - try { - await client.execute({ - method: "calling.transfer", - params: { - node_id: call.nodeId, - call_id: call.callId, - dest: script, - }, - }); - } catch (error) {} +client.onCall(async (call) => { + await call.transfer(script); }); + +await client.run(); ``` + + -In this snippet, we are registering an event for every time a call is received to any phone number in your project with the topic "swml". -You can set the topics a number is subscribed to from the phone number settings page in the SignalWire Dashboard. -Every time a call is received, the SWML script is executed using the `client.execute` method. +The handler subscribes to the topic `swml`, so it receives every call to a phone number whose call handler is a [Relay Application](/docs/platform/glossary#relay-application) with that topic. +You set a number's handler under **Inbound Call Settings** on the number's page in the SignalWire Dashboard. +When a call arrives, the handler transfers it to the SWML document, which takes over the call. +The transfer destination can be an inline SWML document, as here, or the URL of a server that returns one. ## Next steps