playback.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. }
  24. action := map[string]string{
  25. "Action": "Originate",
  26. "Channel": Chan,
  27. "Exten": "000",
  28. "CallerID": PaType,
  29. "Context": "broadcast-playfile",
  30. "Priority": "1",
  31. "Variable": Para,
  32. }
  33. lfshook.NewLogger().Logger.Infof("===action : %+v", action)
  34. res, _, err := AminInstance.Send(action)
  35. if err != nil {
  36. return err
  37. }
  38. if res["Response"] != "Success" {
  39. alstatus.PaStatus("", PaType, "fail")
  40. return errors.New(res["Message"])
  41. }
  42. return nil
  43. }