playback.go 1.1 KB

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