| 1 | # Asterisk to Go [![GoDoc][doc-img]][doc] [![Build Status][ci-img]][ci] [![Coverage Status][cov-img]][cov] [![Go Report Card][report-card-img]][report-card] |
| 2 | |
| 3 | Libs for Golang to work with Asterisk |
| 4 | |
| 5 | * AMI |
| 6 | * AGI |
| 7 | |
| 8 | [doc-img]: http://img.shields.io/badge/GoDoc-Reference-blue.svg |
| 9 | [doc]: https://pkg.go.dev/github.com/wenerme/astgo |
| 10 | |
| 11 | [ci-img]: https://github.com/wenerme/astgo/actions/workflows/ci.yml/badge.svg |
| 12 | [ci]: https://github.com/wenerme/astgo/actions/workflows/ci.yml |
| 13 | |
| 14 | [cov-img]: https://codecov.io/gh/wenerme/astgo/branch/master/graph/badge.svg |
| 15 | [cov]: https://codecov.io/gh/wenerme/astgo/branch/master |
| 16 | |
| 17 | [report-card-img]: https://goreportcard.com/badge/github.com/wenerme/astgo |
| 18 | [report-card]: https://goreportcard.com/report/github.com/wenerme/astgo |
| 19 | |
| 20 | ## AMI |
| 21 | |
| 22 | * Async Action |
| 23 | * Sync Action |
| 24 | * Event Subscribe |
| 25 | * Auto Reconnect |
| 26 | * Generated Action with document |
| 27 | * Generated Event with document |
| 28 | * Generated Client - Action -> Response |
| 29 | |
| 30 | ```go |
| 31 | package main |
| 32 | |
| 33 | import ( |
| 34 | "context" |
| 35 | "fmt" |
| 36 | "github.com/wenerme/astgo/ami" |
| 37 | ) |
| 38 | |
| 39 | func main() { |
| 40 | boot := make(chan *ami.Message, 1) |
| 41 | |
| 42 | conn, err := ami.Connect( |
| 43 | "192.168.1.1:5038", |
| 44 | ami.WithAuth("admin", "admin"), // AMI auth |
| 45 | // add predefined subscriber |
| 46 | ami.WithSubscribe(ami.SubscribeFullyBootedChanOnce(boot)), |
| 47 | ami.WithSubscribe(func(ctx context.Context, msg *ami.Message) bool { |
| 48 | fmt.Println(msg.Format()) // log everything |
| 49 | return true // keep subscribe |
| 50 | }, ami.SubscribeSend(), // subscribe send message - default recv only |
| 51 | )) |
| 52 | if err != nil { |
| 53 | panic(err) |
| 54 | } |
| 55 | <-boot |
| 56 | // AMI now FullyBooted |
| 57 | _ = conn |
| 58 | } |
| 59 | ``` |
| 60 | |
| 61 | ## AGI |
| 62 | |
| 63 | * FastAGI |
| 64 | * AGI Bin |
| 65 | * Generated Command |
| 66 | * Generated Client |
| 67 | |
| 68 | ```go |
| 69 | package main |
| 70 | |
| 71 | import ( |
| 72 | "github.com/wenerme/astgo/agi" |
| 73 | ) |
| 74 | |
| 75 | func main() { |
| 76 | // agi.Listen for FastAGI |
| 77 | agi.Run(func(session *agi.Session) { |
| 78 | client := session.Client() |
| 79 | client.Answer() |
| 80 | client.StreamFile("activated", "#") |
| 81 | client.SetVariable("AGISTATUS", "SUCCESS") |
| 82 | client.Hangup() |
| 83 | }) |
| 84 | } |
| 85 | ``` |
| 86 | |
| 87 | ## Asterisk Database Model |
| 88 | * GORM Based Model |
| 89 | |
| 90 | ## Roadmap |
| 91 | * [-] Asterisk Database Model |
| 92 | * [ ] Stasis |
| 93 | * [ ] ARI |