playback.go 1.0 KB

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