Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #43 from avinashdhinwa/issue-39-ncco
Browse files Browse the repository at this point in the history
Ncco now implements marshaller interface, no need to call `GetActions` for marshalling Ncco
  • Loading branch information
Lorna Jane Mitchell authored Oct 5, 2020
2 parents f746f33 + f11b8db commit 72973a3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 60 deletions.
2 changes: 1 addition & 1 deletion docs/examples/voice.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func answer(w http.ResponseWriter, req *http.Request) {
talk := ncco.TalkAction{Text: "Thank you for calling."}
MyNcco.AddAction(talk)

data, _ := json.Marshal(MyNcco.GetActions())
data, _ := json.Marshal(MyNcco)
fmt.Fprintf(w, "%s", data)
}

Expand Down
10 changes: 0 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,7 @@ require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/google/uuid v1.1.1
github.com/jarcoal/httpmock v1.0.4
github.com/mitchellh/go-homedir v1.1.0
github.com/pelletier/go-toml v1.6.0 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v0.0.6
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.6.2
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect
golang.org/x/text v0.3.2 // indirect
gopkg.in/ini.v1 v1.52.0 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)
33 changes: 0 additions & 33 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
Expand All @@ -52,7 +51,6 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/jarcoal/httpmock v1.0.4 h1:jp+dy/+nonJE4g4xbVtl9QdrUNbn6/3hDT5R4nDIZnA=
github.com/jarcoal/httpmock v1.0.4/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
Expand All @@ -62,8 +60,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
Expand All @@ -73,8 +69,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.6.0 h1:aetoXYr0Tv7xRU/V4B4IZJ2QcbtMUFoNb3ORp7TzIK4=
github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
Expand All @@ -90,38 +84,25 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.6 h1:breEStsVwemnKh2/s6gMvSdMEkwW0sK8vGStnlVBMCs=
github.com/spf13/cobra v0.0.6/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
github.com/spf13/viper v1.6.2 h1:7aKfF+e8/k68gda3LOjo5RxiUqddoFxVq4BKBPrxk5E=
github.com/spf13/viper v1.6.2/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/vonage/vonage-go-sdk v0.8.1 h1:1v/ZuO9Elr+BYLo8SKbrir5TtrOQED6WrgLKSn1MsD0=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
Expand Down Expand Up @@ -153,18 +134,12 @@ golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
Expand All @@ -174,16 +149,8 @@ google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ij
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.52.0 h1:j+Lt/M1oPPejkniCg1TkWE2J3Eh1oZTsHSXzMTzUXn4=
gopkg.in/ini.v1 v1.52.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
6 changes: 6 additions & 0 deletions ncco/ncco.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ncco

import (
"encoding/json"
"strconv"
"strings"
)
Expand All @@ -26,6 +27,11 @@ func (n *Ncco) GetActions() []interface{} {
return n.actions
}

// MarshalJSON to return the NCCO array, ready to be JSON Marshalled
func (n Ncco) MarshalJSON() ([]byte, error) {
return json.Marshal(n.GetActions())
}

// TalkAction is a text-to-speech feature. Beware that the "Loop"
// field is a string here, and the CalculatedLoopValue is used to
// assemble the correct value when sending
Expand Down
26 changes: 13 additions & 13 deletions ncco/ncco_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestNccoTalkSimple(t *testing.T) {
}

// check the JSON
j, _ := json.Marshal(ncco.GetActions())
j, _ := json.Marshal(ncco)
if string(j) != "[{\"action\":\"talk\",\"text\":\"Hello\",\"bargeIn\":false,\"loop\":1}]" {
t.Errorf("Unexpected JSON format for: simple Talk")
}
Expand All @@ -28,7 +28,7 @@ func TestNccoTalkAll(t *testing.T) {
ncco.AddAction(talk)

// check the JSON
j, _ := json.Marshal(ncco.GetActions())
j, _ := json.Marshal(ncco)
if string(j) != "[{\"action\":\"talk\",\"text\":\"Hello\",\"bargeIn\":true,\"level\":1,\"voiceName\":\"Nicole\",\"loop\":4}]" {
t.Errorf("Unexpected JSON format for: All Talk fields")
}
Expand All @@ -44,7 +44,7 @@ func TestNccoNotify(t *testing.T) {
ncco.AddAction(ping)

// check the JSON
j, _ := json.Marshal(ncco.GetActions())
j, _ := json.Marshal(ncco)
if string(j) != "[{\"action\":\"notify\",\"payload\":{\"count\":\"7\",\"key\":\"If that is a key, this is a value\"},\"eventUrl\":[\"https://example.com/notify\"],\"eventMethod\":\"POST\"}]" {
t.Errorf("Unexpected JSON format for: Notify action")
}
Expand All @@ -56,7 +56,7 @@ func TestNccoRecordSimple(t *testing.T) {
ncco.AddAction(record)

// check the JSON
j, _ := json.Marshal(ncco.GetActions())
j, _ := json.Marshal(ncco)
if string(j) != "[{\"action\":\"record\"}]" {
t.Errorf("Unexpected JSON format for: simple Record")
}
Expand All @@ -69,7 +69,7 @@ func TestNccoRecordAll(t *testing.T) {
ncco.AddAction(record)

// check the JSON
j, _ := json.Marshal(ncco.GetActions())
j, _ := json.Marshal(ncco)
if string(j) != "[{\"action\":\"record\",\"format\":\"ogg\",\"split\":\"conversation\",\"channels\":8,\"endOnSilence\":5,\"endOnKey\":\"#\",\"timeOut\":10,\"beepStart\":true,\"eventUrl\":[\"https://example.com/record\"],\"eventMethod\":\"GET\"}]" {
t.Errorf("Unexpected JSON format for: Record all")
}
Expand All @@ -81,7 +81,7 @@ func TestNccoConversationSimple(t *testing.T) {
ncco.AddAction(conversation)

// check the JSON
j, _ := json.Marshal(ncco.GetActions())
j, _ := json.Marshal(ncco)
if string(j) != "[{\"action\":\"conversation\",\"name\":\"convo1\",\"startOnEnter\":true}]" {
t.Errorf("Unexpected JSON format for: simple Conversation")
}
Expand All @@ -94,7 +94,7 @@ func TestNccoConversationAll(t *testing.T) {
ncco.AddAction(conversation)

// check the JSON
j, _ := json.Marshal(ncco.GetActions())
j, _ := json.Marshal(ncco)
if string(j) != "[{\"action\":\"conversation\",\"name\":\"convo1\",\"musicOnHoldUrl\":[\"https://example.com/music.mp3\"],\"endOnExit\":true,\"record\":true,\"startOnEnter\":false}]" {
t.Errorf("Unexpected JSON format for: Conversation all")
}
Expand All @@ -108,7 +108,7 @@ func TestNccoConnectSimplePhone(t *testing.T) {
ncco.AddAction(connect)

// check the JSON
j, _ := json.Marshal(ncco.GetActions())
j, _ := json.Marshal(ncco)
if string(j) != "[{\"action\":\"connect\",\"endpoint\":[{\"type\":\"phone\",\"number\":\"447770007777\"}],\"from\":\"447770008888\"}]" {
t.Errorf("Unexpected JSON format for: simple Connect phone")
}
Expand All @@ -123,7 +123,7 @@ func TestNccoConnectAllPhone(t *testing.T) {
ncco.AddAction(connect)

// check the JSON
j, _ := json.Marshal(ncco.GetActions())
j, _ := json.Marshal(ncco)
if string(j) != "[{\"action\":\"connect\",\"endpoint\":[{\"type\":\"phone\",\"number\":\"447770007777\",\"dtmfAnswer\":\"41\"}],\"from\":\"447770008888\",\"timeout\":3,\"limit\":5,\"machineDetection\":\"continue\",\"eventUrl\":[\"https://example.com/event\"],\"eventMethod\":\"GET\"}]" {
t.Errorf("Unexpected JSON format for: simple Connect phone")
}
Expand All @@ -135,7 +135,7 @@ func TestNccoStreamSimple(t *testing.T) {
ncco.AddAction(stream)

// check the JSON
j, _ := json.Marshal(ncco.GetActions())
j, _ := json.Marshal(ncco)
if string(j) != "[{\"action\":\"stream\",\"streamUrl\":[\"https://example.com/music.mp3\"],\"bargeIn\":false,\"loop\":1}]" {
t.Errorf("Unexpected JSON format for: simple Stream")
}
Expand All @@ -147,7 +147,7 @@ func TestNccoStreamOptions(t *testing.T) {
ncco.AddAction(stream)

// check the JSON
j, _ := json.Marshal(ncco.GetActions())
j, _ := json.Marshal(ncco)
if string(j) != "[{\"action\":\"stream\",\"streamUrl\":[\"https://example.com/music.mp3\"],\"level\":1,\"bargeIn\":true,\"loop\":4}]" {
t.Errorf("Unexpected JSON format for: Stream options")
}
Expand All @@ -159,7 +159,7 @@ func TestNccoInputDtmfEmpty(t *testing.T) {
ncco.AddAction(dtmf)

// check the JSON
j, _ := json.Marshal(ncco.GetActions())
j, _ := json.Marshal(ncco)
if string(j) != "[{\"action\":\"input\",\"dtmf\":{}}]" {
t.Errorf("Unexpected JSON format for: Input DTMF empty")
}
Expand All @@ -171,7 +171,7 @@ func TestNccoInputDtmfOptions(t *testing.T) {
ncco.AddAction(dtmf)

// check the JSON
j, _ := json.Marshal(ncco.GetActions())
j, _ := json.Marshal(ncco)
// fmt.Println(string(j))
if string(j) != "[{\"action\":\"input\",\"dtmf\":{\"timeOut\":8,\"maxDigits\":2,\"submitOnHash\":true},\"eventUrl\":[\"https://example.com/event\"],\"eventMethod\":\"GET\"}]" {
t.Errorf("Unexpected JSON format for: Input DTMF options")
Expand Down
6 changes: 3 additions & 3 deletions voice.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ type TransferWithUrlOpts struct {
}

type TransferDestinationNcco struct {
Type string `json:"type"`
Ncco []interface{} `json:"ncco"`
Type string `json:"type"`
Ncco ncco.Ncco `json:"ncco"`
}

type TransferWithNccoOpts struct {
Expand Down Expand Up @@ -302,7 +302,7 @@ func (client *VoiceClient) TransferCall(opts TransferCallOpts) (ModifyCallRespon
return ModifyCallResponse{Status: "0"}, VoiceErrorResponse{}, nil
}
} else if len(opts.Ncco.GetActions()) > 0 {
destination := TransferDestinationNcco{Type: "ncco", Ncco: opts.Ncco.GetActions()}
destination := TransferDestinationNcco{Type: "ncco", Ncco: opts.Ncco}
transfer := TransferWithNccoOpts{Action: "transfer", Destination: destination}
modifyCallOpts := voice.ModifyCallOpts{Opts: optional.NewInterface(transfer)}
ctx := context.Background()
Expand Down

0 comments on commit 72973a3

Please sign in to comment.