SipBot
A flexible, high-performance SIP bot implementation in Rust, designed for testing and simulating SIP call flows. It uses rsipstack for signaling and supports customizable call handling stages including ringing, answering, media playback, echo, and automatic hangup.
The media transport uses rustrtc.
Features
- Multi-Account Support: Configure multiple SIP accounts in a single instance.
- Flexible Call Flow Stages:
- Ringing (Stage 1): Send
180 Ringingor183 Session Progresswith custom ringback tone (WAV). - Answer (Stage 2): Auto-answer calls with
200 OK. - Media Handling:
- Play: Play a specified
.wavfile. - Echo: Echo received RTP packets back to the sender (Latency testing).
- Play: Play a specified
- Hangup (Stage 3): Automatically hang up after a configurable duration or reject calls with specific SIP codes.
- Ringing (Stage 1): Send
- Outbound Calls: Ability to initiate calls to a target URI.
- Call Recording: (Experimental) Record call audio to WAV files.
- Registration: Supports SIP registration with authentication (WIP).
Quick start
Install the sipbot from crates.io.
CLI Usage
You can also run sipbot with CLI arguments for quick testing.
Global Options
-C, --conf <FILE>: Path to the configuration file.-E, --external-ip <IP>: External IP address for SDP (NAT traversal).
Initiate a Call
--target: The SIP URI to call.--caller: The caller's SIP URI or username.--play-file: Path to a WAV file to play when the call is answered.--hangup: Hangup after specified seconds.
Wait for Calls
Configuration
Create a config.toml file in the root directory. The configuration allows you to define the behavior for each account.
Example config.toml
# Global settings
= "0.0.0.0:5060" # Local bind address
= "1.2.3.4" # External IP for SDP (NAT traversal)
= "/tmp/recorders" # Directory for recordings
[[]]
= "1001"
= "sip.example.com"
= "secretpassword"
= true # Enable registration
# --- Call Handling Flow ---
# Stage 1: Ringing
# Wait for 5 seconds before answering.
# If 'ringback' is provided, sends 183 Session Progress and plays the file.
# If 'ringback' is omitted, sends 180 Ringing.
[]
= 5
# ringback = "sounds/ringback.wav"
# Stage 2: Answer
# Answer the call (200 OK) and perform an action.
[]
= "play" # Options: "play", "echo"
= "sounds/welcome.wav" # Required if action is "play"
# [accounts.answer]
# action = "echo" # Alternative: Echo test
# Stage 3: Hangup
# Automatically hang up after the media finishes or a timeout.
[]
= 200 # SIP code (not fully used for BYE yet, mainly for rejection)
= 10 # Send BYE after 10 seconds
Configuration Reference
addr: (Optional) The local IP and port to bind to. Defaults to0.0.0.0:35060.external_ip: (Optional) The external IP address to use in SDP offers/answers (useful for NAT).recorders: (Optional) Path to save call recordings.accounts: List of account configurations.username: SIP username.domain: SIP domain/registrar.password: SIP password.register: (Bool) Whether to register with the domain.target: (Optional) URI to call on startup (for outbound bot).ring: Configuration for the ringing phase.duration_secs: How long to stay in ringing state.ringback: (Optional) Path to WAV file for early media (183).
answer: Configuration for the answered phase.action:playorecho.wav_file: Path to WAV file (if action isplay).
hangup: Configuration for ending the call.code: SIP status code (used for rejection if no answer config exists).after_secs: (Optional) Time in seconds to wait before sending BYE.
License
MIT