package action import ( "errors" "fmt" "pbx-api-gin/internal/app/ami" "strings" ) func Playback(filename string, count int, exten string, timelen int, delay int) (err error) { Para := fmt.Sprintf("count=%d,timelen=%d,filename=%s,delay=%d", count, timelen, strings.Replace(filename, ".wav", "", -1), delay) Chan := fmt.Sprintf("Local/%s", exten) action := map[string]string{ "Action": "Originate", "Channel": Chan, "Exten": exten, "Context": "broadcast-playfile", "Priority": "1", "Variable": Para, } res, _, err := ami.AminInstance.Send(action) if err != nil { return err } if res["Response"] != "Success" { return errors.New(res["Message"]) } return nil }