call.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. package action
  2. import (
  3. "errors"
  4. "fmt"
  5. "pbx-api-gin/internal/app/stc/active"
  6. "pbx-api-gin/internal/app/stc/priority"
  7. alstatus "pbx-api-gin/internal/app/stc/sendstatus"
  8. "pbx-api-gin/pkg/lfshook"
  9. "pbx-api-gin/pkg/utils"
  10. "sort"
  11. "strings"
  12. "time"
  13. )
  14. var Pads = []string{"2413", "2414", "2415", "2421", "2422", "2423", "2424", "2425", "2431", "2432", "2433", "2434", "2435", "2441", "2442", "2443", "2444",
  15. "2445", "2451", "2452", "2453", "2454", "2455", "2461", "2462", "2463", "2464", "2465", "2471", "2472", "2473", "2474", "2475", "2481", "2482", "2483",
  16. "2484", "2485", "2411", "2412"}
  17. var Pacus = []string{"2111", "2121", "2131", "2141", "2151", "2161", "2171", "2181"}
  18. var Speakers = []string{"2111", "2121", "2131", "2141", "2151", "2161", "2171", "2181", "2311", "2381"}
  19. // Function triggered before no cab occupied signal interrupt
  20. func InActiveHangup() {
  21. if active.ActivedCab == "" {
  22. HangupTask("PA")
  23. HangupTask("CPA")
  24. HangupTask("VOL")
  25. HangupTask("PAD-OCC")
  26. } else {
  27. HangupTask("PA")
  28. HangupTask("PAD-OCC")
  29. HangupTask("CPA")
  30. HangupTask("EMG")
  31. HangupTask("SPC")
  32. HangupTask("DCS")
  33. HangupTask("STN")
  34. HangupTask("CHK")
  35. HangupTask("VOL")
  36. }
  37. }
  38. // Hangup 挂断指定分机或通道
  39. func Hangup(channel string) {
  40. lfshook.NewLogger().Infof("Hangup extensions/channel :%s", channel)
  41. if !utils.IsChannel(channel) {
  42. channel = fmt.Sprintf(`/^(PJ)?SIP\/%s-.*$/`, channel)
  43. }
  44. action := map[string]string{
  45. "Action": "hangup",
  46. "Channel": channel,
  47. }
  48. //lfshook.NewLogger().Infof("hangup action :%+v", action)
  49. if _, _, err := AminInstance.Send(action); err != nil {
  50. lfshook.NewLogger().Errorf("Hangup %+v", err)
  51. }
  52. }
  53. // Hangup 挂断所有分机,除指定分机和PAD
  54. func HangupAllExcept(caller string) {
  55. //all PACU
  56. for _, ret := range Pacus {
  57. Hangup(ret)
  58. }
  59. switch caller {
  60. case "2311":
  61. Hangup("1411") //IO1
  62. Hangup("1481") //IO8
  63. //Hangup("2311") //ICP1
  64. Hangup("2381") //ICP8
  65. case "2381":
  66. Hangup("1411") //IO1
  67. Hangup("1481") //IO8
  68. Hangup("2311") //ICP1
  69. //Hangup("2381") //ICP8
  70. case "1411":
  71. //Hangup("1411") //IO1
  72. Hangup("1481") //IO8
  73. Hangup("2311") //ICP1
  74. Hangup("2381") //ICP8
  75. case "1481":
  76. Hangup("1411") //IO1
  77. //Hangup("1481") //IO8
  78. Hangup("2311") //ICP1
  79. Hangup("2381") //ICP8
  80. case "":
  81. Hangup("1411") //IO1
  82. Hangup("1481") //IO8
  83. Hangup("2311") //ICP1
  84. Hangup("2381") //ICP8
  85. }
  86. }
  87. // Hangup task
  88. func HangupTask(TaskName string) {
  89. lfshook.NewLogger().Infof("HangupTask Check TaskName:%s ", TaskName)
  90. if TaskName == "PAD-OCC" {
  91. resCaller, err := QueueStatus("0301", "") // check OCC queue, get entries
  92. if err != nil {
  93. lfshook.NewLogger().Infof("QueueStatus err:%+v", err)
  94. return
  95. }
  96. for _, caller := range resCaller.Entrys {
  97. //lfshook.NewLogger().Infof("===QueueStatus=entry=%+v", caller)
  98. time.Sleep(time.Millisecond * 50)
  99. RedirectInQueue(caller.CallerIDNum, "0300", "queues-icp-redirect", caller.CallerIDNum) // redirect All PAD redirect to ICP queue
  100. }
  101. }
  102. taskInfo, ok := priority.RegistryTask.Get(TaskName)
  103. if ok {
  104. HangupAllLocalChan()
  105. ConfbridgeKick(taskInfo.ConfbridgeID, "all")
  106. Hangup(taskInfo.RunChannel)
  107. }
  108. }
  109. // interrupt the running task
  110. func InterruptRunningTask(toRunTask string) {
  111. var task priority.TaskInfo
  112. var taskName string
  113. var ok bool
  114. lfshook.NewLogger().Infof("InterruptRunningTask toRuntask:%s ", toRunTask)
  115. if toRunTask != "PA" && toRunTask != "PAD-ICP" && toRunTask != "PAD-TMS" { // ignore C2C
  116. taskName, task, ok = priority.RegistryTask.HighestPriorityRunningTask1()
  117. if !ok {
  118. return
  119. }
  120. } else { // have to check C2C
  121. taskName, task, ok = priority.RegistryTask.HighestPriorityRunningTask()
  122. if !ok {
  123. return
  124. }
  125. }
  126. //same type return
  127. if toRunTask == taskName {
  128. if toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" || toRunTask == "PAD-OCC" {
  129. //Auto Answer PAD-OCC one by one, clean the old confbridge and channels before answer a new PAD .
  130. if toRunTask == "PAD-OCC" {
  131. Hangup(task.RunChannel) //pad
  132. ConfbridgeKick(task.ConfbridgeID, "all")
  133. HangupIO() //io
  134. //lfshook.NewLogger().Infof("===InterruptRunningTask=ret==== ")
  135. }
  136. return
  137. }
  138. }
  139. //pad all reset
  140. if toRunTask == "AlarmHoldResetAll" {
  141. HangupAllLocalChan()
  142. return
  143. }
  144. switch task.RunType {
  145. case "CPA":
  146. //kick CPA members
  147. CPAConfbridgeKick(task.ConfbridgeID)
  148. case "EMG":
  149. //kick EMG members
  150. EMGConfbridgeKick(task.ConfbridgeID)
  151. case "C2C": // Interrupt C2C task running,
  152. if toRunTask == "PA" || toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" {
  153. HangupICP()
  154. return
  155. }
  156. case "PAD-ICP", "PAD-TMS": // Interrupt PAD task running,
  157. priority.InterruptedPad = "PAD-ICP"
  158. lfshook.NewLogger().Infof("InterruptRunningTask interrupt PAD-ICP/PAD-TMS ,Running type :%s !", task.RunType)
  159. chans, err := CoreShowChannels()
  160. if err != nil {
  161. lfshook.NewLogger().Infof("InterruptRunningTask CoreShowChannels err:%+v", err)
  162. return
  163. }
  164. //1. Redirect the connected PAD to 0300,hangup the other pad channel
  165. for _, ret := range chans {
  166. // Redirect the connected PAD to 0300
  167. if utils.IsPAIU(ret.CallerIDNum) {
  168. if ret.ConnectedLineNum == "<unknown>" { //redirect pad chanspy channel
  169. err := Redirect(ret.Channel, "0300", "queues-icp-redirect", "", "PAD")
  170. if err != nil {
  171. lfshook.NewLogger().Infof("InterruptRunningTask Redirect err:%+v", err)
  172. return
  173. }
  174. number := strings.Split(strings.Split(ret.Channel, "-")[0], "/")[1]
  175. active.NotifyPaiu(number, "hold")
  176. //HangupAllLocalChan()
  177. }
  178. }
  179. }
  180. for _, ret := range chans {
  181. //hangup pad call ICP channel
  182. if utils.IsPAIU(ret.CallerIDNum) {
  183. if utils.IsPAIU(ret.CallerIDNum) && ret.ChannelStateDesc == "Up" && utils.IsICP(ret.ConnectedLineNum) {
  184. lfshook.NewLogger().Infof("Hangup PAD Channel :%+v", ret.Channel)
  185. Hangup(ret.Channel)
  186. }
  187. }
  188. }
  189. priority.RegistryTask.StopAndUnregister("PAD-ICP")
  190. priority.RegistryTask.StopAndUnregister("PAD-TMS")
  191. //2. hangup task channel (ICP + PACU)
  192. //lfshook.NewLogger().Infof("===InterruptRunningTask=2. hangup task channel === ")
  193. HangupAllLocalChan()
  194. HangupICP()
  195. //pad end
  196. if priority.PADStart == 1 {
  197. alstatus.PaStatus("", "PAD", "end")
  198. priority.PADStart = 0
  199. }
  200. case "PAD-OCC": // Interrupt PAD-OCC task running,
  201. if toRunTask == "C2C" {
  202. HangupICP()
  203. break
  204. } else {
  205. priority.InterruptedPad = "PAD-OCC"
  206. priority.OCCAnswer = 0
  207. resCaller, err := QueueStatus("0301", "") // check OCC queue, get entries
  208. if err != nil {
  209. lfshook.NewLogger().Infof("QueueStatus err:%+v", err)
  210. return
  211. }
  212. for _, caller := range resCaller.Entrys {
  213. //lfshook.NewLogger().Infof("===QueueStatus=entry=%+v", caller)
  214. time.Sleep(time.Millisecond * 50)
  215. RedirectInQueue(caller.CallerIDNum, "0300", "queues-icp-redirect", caller.CallerIDNum) // redirect All PAD redirect to ICP queue
  216. }
  217. priority.RegistryTask.StopAndUnregister("PAD-OCC")
  218. //2. Hangup connected PAD
  219. //lfshook.NewLogger().Infof("===InterruptRunningTask=Hangup connected PAD=== ")
  220. Hangup(task.RunChannel)
  221. //3. Hangup OI & ICP
  222. HangupIO()
  223. HangupAllLocalChan()
  224. ConfbridgeKick(task.ConfbridgeID, "all")
  225. //occ pad end
  226. if priority.PADOccStart == 1 {
  227. alstatus.OccPad("end")
  228. priority.PADOccStart = 0
  229. }
  230. }
  231. default:
  232. lfshook.NewLogger().Infof("InterruptRunningTask goto default !")
  233. //if !strings.Contains(priority.RunningPATaskChan, "0502@default") {
  234. // Hangup(priority.RunningPATaskChan)
  235. //}
  236. Hangup(task.RunChannel)
  237. ConfbridgeKick(task.ConfbridgeID, "all")
  238. }
  239. }
  240. // Hangup all ICP
  241. func HangupICP() {
  242. Hangup("2311") //ICP1
  243. Hangup("2381") //ICP8
  244. }
  245. // Hangup all IO
  246. func HangupIO() {
  247. Hangup("1411") //IO1
  248. Hangup("1481") //IO8
  249. }
  250. // Hangup all PACU
  251. func HangupAllPACU() {
  252. //all PACU
  253. for _, ret := range Pacus {
  254. Hangup(ret)
  255. }
  256. }
  257. func HangupAllLocalChan() {
  258. chans, err := CoreShowChannels()
  259. if err != nil {
  260. lfshook.NewLogger().Infof("CoreShowChannels %+v", err)
  261. return
  262. }
  263. for _, ret := range chans {
  264. if strings.Contains(ret.Channel, "Local") && !strings.Contains(ret.Channel, "0502@default") {
  265. //lfshook.NewLogger().Infof("HangupAllLocalChan=====hangup========= %+v", ret)
  266. Hangup(ret.Channel)
  267. }
  268. }
  269. }
  270. // Hangup all PACU
  271. func HangupAllPAD() {
  272. //all PAD
  273. for _, ret := range Pads {
  274. Hangup(ret)
  275. }
  276. }
  277. // Hangup all calls
  278. func HangupAll() {
  279. utils.ExecCmdAsync("/usr/sbin/asterisk", "-rx", "hangup request all")
  280. }
  281. // Dial 拨打号码
  282. func Dial(src, dst, dialrule, callerID, callerName string, callType string) {
  283. chanel := fmt.Sprintf("%s/%s@default", "Local", src)
  284. action := map[string]string{
  285. "Action": "Originate",
  286. "Channel": chanel,
  287. "Exten": dst,
  288. "Context": dialrule,
  289. "CallerID": fmt.Sprintf("%s<%s>", callerName, callerID),
  290. "Priority": "1",
  291. "Variable": fmt.Sprintf("CAB=%s", callType),
  292. "async": "true",
  293. }
  294. //lfshook.NewLogger().Infof("dial action %+v", action)
  295. res, _, err := AminInstance.Send(action)
  296. if err != nil {
  297. lfshook.NewLogger().Errorf("%+v", err)
  298. }
  299. lfshook.NewLogger().Info(res)
  300. }
  301. // Dial 拨打号码
  302. func DialICP(src, dst, dialrule, callerID, callerName string) {
  303. chanel := fmt.Sprintf("%s/%s@call-icp", "Local", src)
  304. action := map[string]string{
  305. "Action": "Originate",
  306. "Channel": chanel,
  307. "Exten": dst,
  308. "Context": dialrule,
  309. "CallerID": fmt.Sprintf("%s<%s>", callerName, callerID),
  310. "Priority": "1",
  311. "Variable": fmt.Sprintf("CBID=%s", callerID),
  312. "async": "true",
  313. }
  314. lfshook.NewLogger().Infof("dial action %+v", action)
  315. res, _, err := AminInstance.Send(action)
  316. if err != nil {
  317. lfshook.NewLogger().Errorf("%+v", err)
  318. }
  319. lfshook.NewLogger().Info(res)
  320. }
  321. // 获取分机状态
  322. func ExtenStatus(exten string) (Status string) {
  323. action := map[string]string{
  324. "Action": "ExtensionState",
  325. "Exten": exten,
  326. "Context": "default",
  327. }
  328. res, _, err := AminInstance.Send(action)
  329. if err != nil {
  330. lfshook.NewLogger().Errorf("%+v", err)
  331. return ""
  332. }
  333. //lfshook.NewLogger().Infof("================ExtensionState:res %+v", res)
  334. return res["StatusText"]
  335. }
  336. // PACU ChanSpy
  337. func ChanSpy(src, dst string, whisper, bargein bool) {
  338. lfshook.NewLogger().Infof("chan spy src:%s dst:%s", src, dst)
  339. //channel := fmt.Sprintf("%s/%s", utils.DialPrefix, dst)
  340. channel := fmt.Sprintf("Local/%s@aio-rule", dst)
  341. data := fmt.Sprintf("%s/%s,qBE", utils.DialPrefix, src)
  342. /*
  343. if whisper {
  344. data = fmt.Sprintf("%s,w", data)
  345. }
  346. if bargein {
  347. data = fmt.Sprintf("%s,B", data)
  348. }
  349. */
  350. action := map[string]string{
  351. "Action": "Originate",
  352. "Channel": channel, // 不存在的通话
  353. "Application": "ChanSpy",
  354. "Data": data, // 存在的通话
  355. "CallerID": dst,
  356. "Async": "true",
  357. }
  358. lfshook.NewLogger().Infof("PACU ChanSpy action %+v", action)
  359. _, _, err := AminInstance.Send(action)
  360. if err != nil {
  361. lfshook.NewLogger().Errorf("%+v", err)
  362. }
  363. }
  364. // Redirect 转接
  365. func RedirectInQueue(channel, dst, dialrule, callerID string) (err error) {
  366. //callerID := "redirect"
  367. //lfshook.NewLogger().Infof("redirect src %s to dst %s", channel, dst)
  368. if !utils.IsChannel(channel) {
  369. //callerID = channel
  370. if channel, err = GetChannelByExtenNotBridged(channel); err != nil {
  371. return err
  372. }
  373. }
  374. action := map[string]string{
  375. "Action": "Redirect",
  376. "Channel": channel,
  377. "Exten": dst,
  378. "Context": dialrule,
  379. "CallerID": callerID,
  380. "Priority": "1",
  381. "async": "true",
  382. }
  383. lfshook.NewLogger().Infof("RedirectInQueue: %+v", action)
  384. res, _, err := AminInstance.Send(action)
  385. if err != nil {
  386. lfshook.NewLogger().Error(err)
  387. }
  388. lfshook.NewLogger().Info(res)
  389. return err
  390. }
  391. // Redirect 转接
  392. func Redirect(channel, dst, dialrule, callerID, callerName string) (err error) {
  393. //callerID := "redirect"
  394. //lfshook.NewLogger().Infof("redirect src %s to dst %s", channel, dst)
  395. if !utils.IsChannel(channel) {
  396. callerID = channel
  397. if channel, err = GetChannelByExten(channel); err != nil {
  398. return err
  399. }
  400. }
  401. action := map[string]string{
  402. "Action": "Redirect",
  403. "Channel": channel,
  404. "Exten": dst,
  405. "Context": dialrule,
  406. "CallerID": fmt.Sprintf("%s<%s>", callerName, callerID),
  407. "Priority": "1",
  408. "async": "true",
  409. }
  410. lfshook.NewLogger().Infof("Redirect: %+v", action)
  411. res, _, err := AminInstance.Send(action)
  412. if err != nil {
  413. lfshook.NewLogger().Error(err)
  414. }
  415. lfshook.NewLogger().Info(res)
  416. return err
  417. }
  418. func SetPadTimer() {
  419. toRunPadpriority := priority.GetPriorityByKey(priority.InterruptedPad) //Get PAD priori 获取之前打断的报警优先级
  420. //toRunpriority := priority.GetPriorityByKey("PAD-ICP")
  421. _, taskTmp, ok := priority.RegistryTask.HighestPriorityRunningTask()
  422. if ok {
  423. lfshook.NewLogger().Infof("PAD SetPadTimer runing priority:%d toRun priority:%d", taskTmp.Priority, toRunPadpriority)
  424. if taskTmp.Priority < toRunPadpriority { //higher priority task running ,do not set timer
  425. return
  426. }
  427. }
  428. res, err := QueueStatus("0300", "") // check OCC queue , if empty OCC-PAD start
  429. if err != nil {
  430. lfshook.NewLogger().Infof("QueueStatus err%+v", err)
  431. return
  432. }
  433. if res.Calls != "0" {
  434. lfshook.NewLogger().Infof("PAD SetPadTimer Set QueueTimer timeout 30s !")
  435. //active.SetTimer = true
  436. //lfshook.NewLogger().Logger.Infof("=========Start PAD timer !=============")
  437. if active.QueueTimer != nil {
  438. if active.QueueTimer.Stop() {
  439. lfshook.NewLogger().Logger.Infof("=========Release PAD timer true !============")
  440. } else {
  441. lfshook.NewLogger().Logger.Infof("=========Release PAD timer false ! ============")
  442. }
  443. }
  444. //active.QueueTimer = time.AfterFunc(time.Duration(active.PADTimeout)*time.Second, func() { // check the PAD 30s timeout
  445. active.QueueTimer = time.AfterFunc(30*time.Second, func() { // check the PAD 30s timeout
  446. //if both not active , return
  447. if active.ActivedCab == "" {
  448. return
  449. }
  450. res, err := QueueStatus("0301", "") // check OCC queue , if empty OCC-PAD start
  451. if err != nil {
  452. lfshook.NewLogger().Infof("OCC QueueStatus err:%+v", err)
  453. return
  454. }
  455. if res.Calls == "0" { // OCC queue empty
  456. resCaller, err := QueueStatus("0300", "") // check ICP queue, get entries
  457. if err != nil {
  458. lfshook.NewLogger().Infof("ICP QueueStatus err:%+v", err)
  459. return
  460. }
  461. sort.Slice(resCaller.Entrys, func(i, j int) bool {
  462. return resCaller.Entrys[i].Position < resCaller.Entrys[j].Position
  463. })
  464. for _, caller := range resCaller.Entrys {
  465. priority.ICPAnswer = 0
  466. //lfshook.NewLogger().Infof("====SetPadTimer==QueueTimer==2=")
  467. //lfshook.NewLogger().Infof("==SetPadTimer==Redirect to 0301 entry:%s=Pos:%s==", caller.CallerIDNum, caller.Position)
  468. //order by pos
  469. RedirectInQueue(caller.CallerIDNum, "0301", "queues-occ", caller.CallerIDNum) // redirect All ICP-PAD redirect to OCC queue
  470. time.Sleep(time.Millisecond * 100) //200 ms delay
  471. }
  472. }
  473. })
  474. }
  475. }
  476. func ConfbridgeKick(confnum, channel string) (res map[string]string, err error) {
  477. action := map[string]string{
  478. "Action": "ConfbridgeKick",
  479. "Conference": confnum,
  480. "Channel": channel,
  481. }
  482. res, _, err = AminInstance.Send(action)
  483. if err != nil {
  484. return nil, err
  485. }
  486. lfshook.NewLogger().Infof("ConfbridgeKick res:%+v", res)
  487. if res["Response"] != "Success" {
  488. return nil, errors.New(res["Message"])
  489. }
  490. return res, nil
  491. }
  492. func CPAConfbridgeKick(confnum string) (res map[string]string, err error) {
  493. chans, err := ConfbridgeList(confnum)
  494. if err != nil {
  495. return nil, errors.New(res["Message"])
  496. }
  497. for _, confChan := range chans {
  498. if !strings.Contains(confChan, "PJSIP/1481") {
  499. ConfbridgeKick(confnum, confChan)
  500. }
  501. }
  502. return res, nil
  503. }
  504. func CPAConfbridgeReinvite(confID string) {
  505. time.Sleep(time.Millisecond * 500)
  506. for _, ext := range Speakers {
  507. ConfbridgeReinvite(ext, "call-speakers-cpa", confID)
  508. }
  509. }
  510. func EMGConfbridgeKick(confnum string) (res map[string]string, err error) {
  511. chans, err := ConfbridgeList(confnum)
  512. if err != nil {
  513. return nil, errors.New(res["Message"])
  514. }
  515. for _, confChan := range chans {
  516. if !strings.Contains(confChan, "0502@default") {
  517. ConfbridgeKick(confnum, confChan)
  518. }
  519. }
  520. return res, nil
  521. }
  522. func EMGConfbridgeReinvite(confID string) {
  523. time.Sleep(time.Millisecond * 500)
  524. for _, ext := range Speakers {
  525. ConfbridgeReinvite(ext, "call-speakers-emg", confID)
  526. }
  527. }
  528. func ConfbridgeList(confnum string) (chans []string, err error) {
  529. action := map[string]string{
  530. "Action": "ConfbridgeList",
  531. "Conference": confnum,
  532. }
  533. res, events, err := AminInstance.Send(action)
  534. if err != nil {
  535. return nil, err
  536. }
  537. lfshook.NewLogger().Infof("ConfbridgeList res:%+v", res)
  538. if res["Response"] == "Success" {
  539. for _, event := range events {
  540. if event.Data["Event"] == "ConfbridgeList" {
  541. chans = append(chans, event.Data["Channel"])
  542. }
  543. }
  544. return chans, nil
  545. } else {
  546. return nil, errors.New(res["Message"])
  547. }
  548. }
  549. func ConfbridgeReinvite(src, context, confID string) {
  550. if ExtenStatus(src) != "Idle" {
  551. lfshook.NewLogger().Infof(" ConfbridgeReinvite ext:%s Not Idle !", src)
  552. return
  553. }
  554. chanel := fmt.Sprintf("Local/%s@%s", src, context)
  555. action := map[string]string{
  556. "Action": "Originate",
  557. "Channel": chanel,
  558. "Exten": "000",
  559. "Context": "confbridge-join",
  560. "CallerID": fmt.Sprintf("%s<%s>", "", ""),
  561. "Priority": "1",
  562. "Variable": fmt.Sprintf("CBID=%s", confID),
  563. "async": "true",
  564. }
  565. lfshook.NewLogger().Infof("dial action %+v", action)
  566. res, _, err := AminInstance.Send(action)
  567. if err != nil {
  568. lfshook.NewLogger().Errorf("%+v", err)
  569. }
  570. lfshook.NewLogger().Info(res)
  571. }
  572. func ICPConfbridgeReinvite(confID, paType string) {
  573. switch paType {
  574. case "PAD-OCC":
  575. go DialICP("8", "2311", "confbridge-join", confID, "1") //ICP1---call
  576. go DialICP("8", "2381", "confbridge-join", confID, "8") //ICP8---call
  577. case "CPA":
  578. go DialICP("2", "2311", "confbridge-join", confID, "1") //ICP1---call
  579. go DialICP("2", "2381", "confbridge-join", confID, "8") //ICP8---call
  580. case "EMG":
  581. go DialICP("3", "2311", "confbridge-join", confID, "1") //ICP1---call
  582. go DialICP("3", "2381", "confbridge-join", confID, "8") //ICP8---call
  583. case "SPC":
  584. go DialICP("6", "2311", "confbridge-join", confID, "1") //ICP1---call
  585. go DialICP("6", "2381", "confbridge-join", confID, "8") //ICP8---call
  586. case "STN":
  587. go DialICP("4", "2311", "confbridge-join", confID, "1") //ICP1---call
  588. go DialICP("4", "2381", "confbridge-join", confID, "8") //ICP8---call
  589. case "DCS":
  590. go DialICP("5", "2311", "confbridge-join", confID, "1") //ICP1---call
  591. go DialICP("5", "2381", "confbridge-join", confID, "8") //ICP8---call
  592. case "CHK":
  593. go DialICP("10", "2311", "confbridge-join", confID, "1") //ICP1---call
  594. go DialICP("10", "2381", "confbridge-join", confID, "8") //ICP8---call
  595. case "VOL":
  596. go DialICP("11", "2311", "confbridge-join", confID, "1") //ICP1---call
  597. go DialICP("11", "2381", "confbridge-join", confID, "8") //ICP8---call
  598. }
  599. }