playback.go 709 B

123456789101112131415161718192021222324252627282930313233
  1. package action
  2. import (
  3. "errors"
  4. "fmt"
  5. "pbx-api-gin/internal/app/ami"
  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(filename, ".wav", "", -1), delay, PaType)
  10. Chan := "Local/0500" //paging pacu
  11. action := map[string]string{
  12. "Action": "Originate",
  13. "Channel": Chan,
  14. "Exten": "000",
  15. "CallerID": PaType,
  16. "Context": "broadcast-playfile",
  17. "Priority": "1",
  18. "Variable": Para,
  19. }
  20. res, _, err := ami.AminInstance.Send(action)
  21. if err != nil {
  22. return err
  23. }
  24. if res["Response"] != "Success" {
  25. return errors.New(res["Message"])
  26. }
  27. return nil
  28. }