Server bots

@applooma/rtc-server-participant (Node.js) and applooma-bot (Python) join a channel from your server as a participant: a voice agent, a transcription listener, a media relay, a moderation bot. It publishes raw PCM audio and raw video frames, receives everyone else's media as raw frames, and exchanges messages with the client SDKs.

Beta

0.1.0 for both Node and Python. The API may change before 1.0.

Install#

Terminal
npm install @applooma/rtc-server-participant

Node 18 or newer. The media stack ships as prebuilt binaries for linux-x64, linux-arm64, darwin-arm64, darwin-x64 and win32-x64, so no compiler is needed. On any other platform AppBot.join() rejects with the error code unsupported_platform.

Tokens#

A bot uses an ordinary token. Mint it with createToken() from the Node server SDK, with an identity of your choosing and role host to publish or audience to listen only. url is the same wsUrl your token endpoint gives clients.

Example: an echo bot#

echo-bot.ts
import { AppBot } from '@applooma/rtc-server-participant';
const bot = await AppBot.join({ url: process.env.APPLOOMA_WS_URL!, token });
bot.on('userJoined', (u) => console.log(u.uid, 'joined'));
// 16-bit PCM from every speaker, straight back into the channel.
bot.on('audioFrame', (frame) => {
bot.publishAudio(frame).catch((e) => console.error(e.code, e.message));
});
bot.on('message', async (m) => {
if (m.text === '!bye') await bot.leave();
else await bot.sendMessage('echo: ' + (m.text ?? JSON.stringify(m.data)));
});

API#

AppBot.join(options)

OptionDefault
urlrequiredThe channel server URL (wsUrl).
tokenrequiredA token from your server.
autoSubscribetrueReceive other participants’ media.
receiveSampleRate48000Rate of audioFrame events; incoming audio is resampled.
receiveChannels1Channels of audioFrame events.
receiveVideoFormat'rgba''rgba' or 'i420' for videoFrame events.

Publishing

  • publishAudio(frame): interleaved 16-bit PCM. The first call publishes the bot's microphone; later frames keep the same rate and channels. Awaiting each call paces you to real time.
  • publishVideo({ data, width, height, format }): I420 or RGBA. The first call publishes the bot's camera.

Events

EventArguments
audioFrame(frame: { data: Int16Array, sampleRate, channels, samplesPerChannel }, user)
videoFrame(frame: { data: Uint8Array, width, height, format, timestampUs }, user)
message(message: { id, text?, data?, from?, sentAt })
userJoined / userLeft(user: { uid, displayName, role, attributes })
disconnected(reason?)
error(error: AppBotError)

Frames are decoded only for tracks subscribed while an audioFrame or videoFrame listener is attached, so register listeners right after joining.

Messages and leaving

  • sendMessage(text | object) arrives on the client SDKs' message event, like any other participant's.
  • leave() leaves the channel and frees native resources.

Errors

Everything throws or emits AppBotError with a code: unsupported_platform, join_failed, not_joined, invalid_frame, send_failed.

Python#

Terminal
pip install applooma applooma-bot

Python 3.9 or newer, asyncio. Prebuilt wheels for Linux x86_64 and aarch64 (glibc 2.28+), macOS arm64 and x86_64, and Windows x64, so no compiler is needed. The token comes from create_token() in the Python server SDK. The API mirrors the Node one in snake_case; handlers may be plain functions or coroutines.

echo_bot.py
import asyncio
from applooma import AppServerClient
from applooma_bot import AppBot, AppBotError
async def main():
t = AppServerClient(api_key="...", api_secret="...").create_token(
room_name="room1", identity="echo-bot", role="host")
bot = await AppBot.join(url=t["wsUrl"], token=t["token"])
@bot.on("audio_frame") # frame.data: interleaved 16-bit PCM bytes
async def echo(frame, user):
await bot.publish_audio(frame)
@bot.on("message")
async def on_message(msg):
if msg.text == "!bye":
await bot.leave()
else:
await bot.send_message("echo: " + (msg.text or str(msg.data)))
await asyncio.Event().wait()
asyncio.run(main())
NodePython
AppBot.join({ url, token, ... })await AppBot.join(url, token, auto_subscribe=, receive_sample_rate=, receive_channels=, receive_video_format=)
publishAudio(frame)await publish_audio(AppAudioFrame(data, sample_rate, channels))
publishVideo(frame)publish_video(AppVideoFrame(data, width, height, format))
sendMessage(body)await send_message(body)
leave()await leave() / async with bot
audioFrame, videoFrame, userJoined, userLeftaudio_frame, video_frame, user_joined, user_left
message, disconnected, errormessage, disconnected, error

Errors are AppBotError with the same code values as Node. Messages use the same wire format, so Node bots, Python bots and the client SDKs all see each other's messages.