ami.cr
ami.cr
crystal library that interacts with the asterisk manager interface (AMI) asyncronously sending actions and reciving events
Installation
add to shard.yml
dependencies:
ami:
github: edersohe/ami.cr
branch: master
Usage
Connect With asterisk manager ingterface
ami = AMI.open("127.0.0.1", 5038, username: "MyUsername", secret: "MyPassword", events: "all", debug: true)
Create Handler
def print_event_handler(event : AMI::Message)
p event.to_s # AMI message format
p event.to_h # To hash
p event.to_json # To json
end
Send actions to asterisk
ami.action("login", username: "MyUsername", secret: "MyPassword", events: "all").send
ami.action("originate", channel: "PJSIP/6001", context: "from-internal", exten: 100, priority: 1).send
Handle received messages
Pattern match is used once and is removed from handlers
ami.add_handler("Event: ContactStatus\r\n", ->print_event_handler(AMI::Message))
ami.add_handler("Event: Hangup\r\n", ->print_event_handler(AMI::Message))
Pattern match is used all connection life after added it to handlers
ami.add_handler("Event: DialEnd\r\n", ->print_event_handler(AMI::Message), permanent: true)
ami.add_handler("Event: DeviceStateChange(.*\r\n)*State: NOT_INUSE", ->print_event_handler(AMI::Message), permanent: true)
Contributing
- Fork it ( https://github.com/edersohe/ami.cr/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- edersohe Eder Sosa - creator, maintainer
Repository
ami.cr
Owner
Statistic
- 1
- 0
- 0
- 0
- 0
- over 6 years ago
- July 6, 2017
License
MIT License
Links
Synced at
Thu, 07 Nov 2024 10:22:54 GMT
Languages