playback.go 902 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package action
  2. import (
  3. "errors"
  4. "fmt"
  5. "strings"
  6. )
  7. func PlaybackPacu(filename string, count int, delay int, PaType string) (err error) {
  8. Para := fmt.Sprintf("count=%d,filename=%s,delay=%d,priority=%s", count, strings.Replace(filename, ".wav", "", -1), delay, PaType)
  9. Chan := ""
  10. switch PaType {
  11. case "STN":
  12. Chan = "Local/0503" //spa-rule
  13. case "SPC":
  14. Chan = "Local/0505" //spc-rule
  15. case "DCS":
  16. Chan = "Local/0504" //dc-rule
  17. case "CHK":
  18. Chan = "Local/0503" //paging pacu
  19. case "EMG":
  20. Chan = "Local/0502" //emg-rule
  21. }
  22. action := map[string]string{
  23. "Action": "Originate",
  24. "Channel": Chan,
  25. "Exten": "000",
  26. "CallerID": PaType,
  27. "Context": "broadcast-playfile",
  28. "Priority": "1",
  29. "Variable": Para,
  30. }
  31. res, _, err := AminInstance.Send(action)
  32. if err != nil {
  33. return err
  34. }
  35. if res["Response"] != "Success" {
  36. return errors.New(res["Message"])
  37. }
  38. return nil
  39. }