Skip to content

Commit

Permalink
Create a basic README and add an Inbound example.
Browse files Browse the repository at this point in the history
  • Loading branch information
winsock committed Oct 6, 2020
1 parent be1bd6a commit 1de1b2d
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 11 deletions.
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# eslgo
eslgo is a [FreeSWITCH™](https://freeswitch.com/) ESL library for GoLang

## Install
```
go get github.com/percipia/eslgo
```
```
github.com/percipia/eslgo v1.2.1
```

## Overview
- Inbound ESL Connections
- Outbound ESL Server
- Context Support
- Basic Helpers for common tasks
- DTMF
- Call origination
- Call answer/hangup
- Audio playback

## Examples
There are some buildable examples under the `example` directory as well
### Outbound ESL Server
```go
package main

import (
"context"
"fmt"
"github.com/percipia/eslgo"
"log"
"time"
)

func main() {
log.Fatalln(eslgo.ListenAndServe(":8084", handleConnection))
}

func handleConnection(ctx context.Context, conn *eslgo.Conn, response *eslgo.RawResponse) {
fmt.Printf("Got connection! %#v\n", response)
_ = conn.EnableEvents(ctx)
originationUUID, response, err := conn.OriginateCall(ctx, "user/100", "&playback(misc/ivr-to_hear_screaming_monkeys.wav)", map[string]string{})
fmt.Println("Call Originated: ", originationUUID, response, err)
}
```
## Inbound ESL Client
```go
package main

import (
"context"
"fmt"
"github.com/percipia/eslgo"
"time"
)

func main() {
conn, err := eslgo.Dial("127.0.0.1", "ClueCon", func() {
fmt.Println("Inbound Connection Done")
})

ctx, cancel := context.WithTimeout(context.Background(), 5 * time.Minute)
defer cancel()

_ = conn.EnableEvents(ctx)
originationUUID, response, err := conn.OriginateCall(ctx, "user/100", "&playback(misc/ivr-to_hear_screaming_monkeys.wav)", map[string]string{})
fmt.Println("Call Originated: ", originationUUID, response, err)

time.Sleep(60 * time.Second)
}
```
33 changes: 33 additions & 0 deletions example/inbound.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2020 Percipia
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* Contributor(s):
* Andrew Querol <[email protected]>
*/
package main

import (
"context"
"fmt"
"gitlab.percipia.com/libs/go/freeswitchesl"
"time"
)

func main() {
conn, err := freeswitchesl.Dial("127.0.0.1", "ClueCon", func() {
fmt.Println("Inbound Connection Done")
})

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

_ = conn.EnableEvents(ctx)
originationUUID, response, err := conn.OriginateCall(ctx, "user/100", "&playback(misc/ivr-to_hear_screaming_monkeys.wav)", map[string]string{})
fmt.Println("Call Originated: ", originationUUID, response, err)

time.Sleep(60 * time.Second)
}
14 changes: 3 additions & 11 deletions test/main.go → example/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import (
"context"
"fmt"
"gitlab.percipia.com/libs/go/freeswitchesl"
"gitlab.percipia.com/libs/go/freeswitchesl/command"
"log"
"time"
)

func main() {
Expand All @@ -25,13 +23,7 @@ func main() {

func handleConnection(ctx context.Context, conn *freeswitchesl.Conn, response *freeswitchesl.RawResponse) {
fmt.Printf("Got connection! %#v\n", response)
conn.SendCommand(ctx, command.Event{
Format: "plain",
Listen: []string{"ALL"},
})
conn.SendCommand(ctx, command.API{
Command: "originate",
Arguments: "user/100 &park()",
})
time.Sleep(60 * time.Second)
_ = conn.EnableEvents(ctx)
originationUUID, response, err := conn.OriginateCall(ctx, "user/100", "&playback(misc/ivr-to_hear_screaming_monkeys.wav)", map[string]string{})
fmt.Println("Call Originated: ", originationUUID, response, err)
}

0 comments on commit 1de1b2d

Please sign in to comment.