ER

emilianodellacasa/ruby-asterisk

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

76 stars 质量 55 趋势 18MIT

Ruby 中的星号管理器界面

概览

一个适用于Asterisk PBX的Ruby客户端,涵盖三个接口: - - 运行时依赖:异步 ~> 2.0,faraday >= 1.0,websocket-driver ~> 0.8 :非同步光纤调度器所需的IO#超时抖动在AGI模块加载时自动应用——无需操作。 每个 AMI 命令都会立即返回 RubyAsterisk::AMI::P romise ——它确实会阻塞。调用 .value(timeout)以等待响应: disconnect 会拒绝所有带有 RuntimeError 的待处理承诺。 RubyAsterisk的状态值::D ESCRIPTIVE_STATUS:-1 未找到分机 ·0 闲置 ·1 正在使用 ·2 忙碌 ·3 不可用 ·4 铃声 ·5 等待中 DescriptiveStatus 只会为该地图中的状态添加;其他值则不产生任何值。 带结构化数据解析的命令(PARSE_DATA):CoreShowChannels、ParkedCalls、Originate、MeetMeList、ConfbridgeListRooms、ConfbridgeList、Status、ExtensionStateList、DeviceStateList、SKINNYdevices、SKINNYlines、QueuePause、Pong、Events、SIPpeers、SIPshowpeer。

概述(AI 翻译)

一个适用于Asterisk PBX的Ruby客户端,涵盖三个接口:

接口 用例 入口点 并发模型
AMI TCP命令/事件通道 RubyAsterisk::AMI::Client 线程 + 承诺(非阻塞)
ARI HTTP REST 控制 API RubyAsterisk::ARI::Client 同步(法拉第)
ARI WebSocket 实时事件流 RubyAsterisk::ARI::WebSocket Websocket-driver + 线程
AGI / 快速AGI 进程中表盘逻辑 RubyAsterisk::AGI::Server 异步 + 光纤

要求

  • Ruby ≥ 3.1
  • 运行时依赖:async ~> 2.0、faraday >= 1.0、websocket-driver ~> 0.8

Ruby 3.1 注释:非同步光纤调度器所需的 IO#timeout 垫片在加载 AGI 模块时会自动应用——无需操作。

安装

AMI — 星号管理器界面

初始化并连接

承诺模型

每个AMI命令立即返回RubyAsterisk::AMI::Promise——它不会阻塞。呼叫.value(timeout)等待Response:

disconnect 拒绝所有待处理的承诺,并用 RuntimeError。

登录 / 注销

系统命令

频道指令

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

ruby-asterisk

A Ruby client for Asterisk PBX covering three interfaces:

Interface Use case Entry point Concurrency model
AMI TCP command/event channel RubyAsterisk::AMI::Client Threads + Promise (non-blocking)
ARI HTTP REST control API RubyAsterisk::ARI::Client Synchronous (Faraday)
ARI WebSocket Real-time event stream RubyAsterisk::ARI::WebSocket websocket-driver + Threads
AGI / FastAGI In-process dialplan logic RubyAsterisk::AGI::Server Async + Fibers

Requirements

  • Ruby ≥ 3.1
  • Runtime dependencies: async ~> 2.0, faraday >= 1.0, websocket-driver ~> 0.8

Ruby 3.1 note: the IO#timeout shim required by the Async Fiber scheduler is applied automatically when the AGI module is loaded — no action needed.

Installation

gem 'ruby-asterisk'
bundle install

AMI — Asterisk Manager Interface

Initialize and connect

require 'ruby-asterisk'

ami = RubyAsterisk::AMI::Client.new(host: '192.168.1.1', port: 5038)
ami.connect

The Promise model

Every AMI command returns a RubyAsterisk::AMI::Promise immediately — it does not block. Call .value(timeout) to wait for the Response:

promise  = ami.ping          # returns immediately
response = promise.value     # blocks up to 5 s (default)
response = promise.value(10) # custom timeout in seconds

puts response.success        # => true
puts response.message        # => "Pong"
puts response.action_id      # => "lk3m0p..."
puts response.data           # => structured Hash or Array depending on command
puts response.raw_response   # => raw AMI text

# On timeout:
begin
  response = promise.value(2)
rescue Timeout::Error => e
  puts e.message
end

disconnect rejects all pending promises with a RuntimeError.

Login / Logoff

ami.login(username: 'mark', secret: 'mysecret').value
ami.logoff.value

System commands

ami.ping.value
ami.command('core show channels').value
ami.wait_event(timeout: -1).value     # -1 = wait forever: .value blocks until an event arrives
ami.wait_event(timeout: 30).value     # bounded wait; .value gives up after 30 s
ami.event_mask('on').value            # enable event delivery on this connection
ami.parked_calls.value
ami.device_state_list.value
ami.skinny_devices.value
ami.skinny_lines.value

Channel commands

ami.core_show_channels.value
ami.status.value                      # all channels
ami.status(channel: 'SIP/alice-001').value

# Originate: channel, context, callee, priority
ami.originate('SIP/9100', 'OUTGOING', '123456', '1',
              caller_id: 'Alice',
              variable: 'var1=12,var2=99',
              timeout: 30_000,
在 GitHub 查看完整 README

推荐工具

换一个关键词,或者移除筛选条件。

安装

npx skillfish add emilianodellacasa/ruby-asterisk
新手?先看 mcpskill.org 教程 →