From 1de1b2dea8dadb4e87aab46b88330e87e3241719 Mon Sep 17 00:00:00 2001 From: Andrew Querol Date: Tue, 6 Oct 2020 13:20:25 -0500 Subject: [PATCH] Create a basic README and add an Inbound example. --- README.md | 72 +++++++++++++++++++++++++++++ example/inbound.go | 33 +++++++++++++ test/main.go => example/outbound.go | 14 ++---- 3 files changed, 108 insertions(+), 11 deletions(-) create mode 100644 example/inbound.go rename test/main.go => example/outbound.go (69%) diff --git a/README.md b/README.md index e69de29..e49d02e 100644 --- a/README.md +++ b/README.md @@ -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) +} +``` \ No newline at end of file diff --git a/example/inbound.go b/example/inbound.go new file mode 100644 index 0000000..9d2b75f --- /dev/null +++ b/example/inbound.go @@ -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 + */ +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) +} diff --git a/test/main.go b/example/outbound.go similarity index 69% rename from test/main.go rename to example/outbound.go index 7753dac..50ff632 100644 --- a/test/main.go +++ b/example/outbound.go @@ -14,9 +14,7 @@ import ( "context" "fmt" "gitlab.percipia.com/libs/go/freeswitchesl" - "gitlab.percipia.com/libs/go/freeswitchesl/command" "log" - "time" ) func main() { @@ -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) }