You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
5.6 KiB

  1. # Copyright (C) 2018 Voicent
  2. # Copyright (C) 2019 Open Source Integrators
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. #
  5. # Documentation available at https://voicent.com/developer/docs/camp-api/
  6. import ntpath
  7. import requests
  8. import ast
  9. class Voicent():
  10. def __init__(self, host="localhost", port="8155"):
  11. self.host_ = host
  12. self.port_ = port
  13. def postToGateway(self, urlstr, params, files=None):
  14. url = "http://" + self.host_ + ":" + self.port_ + urlstr
  15. res = requests.post(url, params, files=files)
  16. return res.text
  17. def getReqId(self, rcstr):
  18. index1 = rcstr.find("[ReqId=")
  19. if (index1 == -1):
  20. return ""
  21. index1 += 7
  22. index2 = rcstr.find("]", index1)
  23. if (index2 == -1):
  24. return ""
  25. return rcstr[index1:index2]
  26. def callText(self, phoneno, text, selfdelete):
  27. urlstr = "/ocall/callreqHandler.jsp"
  28. params = {
  29. 'info': 'simple text call',
  30. 'phoneno': phoneno,
  31. 'firstocc': 10,
  32. 'txt': text,
  33. 'selfdelete': selfdelete
  34. }
  35. res = self.postToGateway(urlstr, params)
  36. return self.getReqId(res)
  37. def callAudio(self, phoneno, filename, selfdelete):
  38. urlstr = "/ocall/callreqHandler.jsp"
  39. params = {
  40. 'info': 'simple audio call',
  41. 'phoneno': phoneno,
  42. 'firstocc': 10,
  43. 'audiofile': filename,
  44. 'selfdelete': selfdelete
  45. }
  46. res = self.postToGateway(urlstr, params)
  47. return self.getReqId(res)
  48. def callIvr(self, phoneno, appname, selfdelete):
  49. urlstr = "/ocall/callreqHandler.jsp"
  50. params = {
  51. 'info': 'simple text call',
  52. 'phoneno': phoneno,
  53. 'firstocc': 10,
  54. 'startapp': appname,
  55. 'selfdelete': selfdelete
  56. }
  57. res = self.postToGateway(urlstr, params)
  58. return self.getReqId(res)
  59. def callStatus(self, reqid):
  60. urlstr = "/ocall/callstatusHandler.jsp"
  61. params = {'reqid': reqid}
  62. res = self.postToGateway(urlstr, params)
  63. return self.getReqId(res)
  64. def callRemove(self, reqId):
  65. urlstr = "/ocall/callremoveHandler.jsp"
  66. params = {'reqid': reqId}
  67. res = self.postToGateway(urlstr, params)
  68. return self.getReqId(res)
  69. def callTillConfirm(self, vcastexe, vocfile, wavfile, ccode):
  70. urlstr = "/ocall/callreqHandler.jsp"
  71. cmdline = "\""
  72. cmdline += vocfile
  73. cmdline += "\""
  74. cmdline += " -startnow"
  75. cmdline += " -confirmcode "
  76. cmdline += ccode
  77. cmdline += " -wavfile "
  78. cmdline += "\""
  79. cmdline += wavfile
  80. cmdline += "\""
  81. params = {
  82. 'info': 'Simple Call till Confirm',
  83. 'phoneno': '1111111',
  84. 'firstocc': 10,
  85. 'selfdelete': 0,
  86. 'startexec': vcastexe,
  87. 'cmdline': cmdline
  88. }
  89. res = self.postToGateway(urlstr, params)
  90. return self.getReqId(res)
  91. ################
  92. # CAMPAIGN API #
  93. ################
  94. def importCampaign(self, listname, filepath):
  95. urlstr = "/ocall/campapi"
  96. params = {
  97. 'action': 'import',
  98. 'importfile': ntpath.basename(filepath),
  99. 'importfilepath': filepath,
  100. 'profile': 'Test',
  101. 'mod': 'cus',
  102. 'fieldsep': ',',
  103. 'row1': 1,
  104. 'mergeopt': 'empty',
  105. 'leadsrcname': listname
  106. }
  107. files = {
  108. 'file': (ntpath.basename(filepath), open(filepath, 'rb'))
  109. }
  110. res = self.postToGateway(urlstr, params, files)
  111. return ast.literal_eval(res)
  112. def runCampaign(self, listname):
  113. urlstr = "/ocall/campapi"
  114. params = {
  115. 'action': 'bbp',
  116. 'CAMP_NAME': 'Test',
  117. 'listname': listname,
  118. 'phonecols': 'Phone',
  119. 'lines': '4',
  120. 'calldisps': '',
  121. 'callerid': '+18884728568',
  122. }
  123. res = self.postToGateway(urlstr, params)
  124. return ast.literal_eval(res)
  125. def importAndRunCampaign(self, filepath, msgtype, msginfo):
  126. urlstr = "/ocall/campapi"
  127. params = {
  128. 'action': 'bbp',
  129. # Parameters for importing the campaign
  130. 'importfile': ntpath.basename(filepath),
  131. 'importfilepath': filepath,
  132. # 'profile': 'Test',
  133. 'mod': 'cus',
  134. 'row1': 1,
  135. 'leadsrcname': 'Test',
  136. # Parameters for running the campaign
  137. 'CAMP_NAME': 'Test',
  138. 'phonecols': 'Phone',
  139. 'lines': '4',
  140. 'calldisps': '',
  141. 'callerid': '+18884728568',
  142. # Parameters for Autodialer
  143. 'msgtype': msgtype,
  144. 'msginfo': msginfo,
  145. }
  146. files = {
  147. 'file': (ntpath.basename(filepath), open(filepath, 'rb'))
  148. }
  149. res = self.postToGateway(urlstr, params, files)
  150. return ast.literal_eval(res)
  151. def checkStatus(self, leadsrc_id):
  152. urlstr = "/ocall/campapi"
  153. params = {
  154. 'action': 'campstats',
  155. 'leadsrc_id': leadsrc_id
  156. }
  157. res = self.postToGateway(urlstr, params)
  158. return ast.literal_eval(res)
  159. def exportResult(self, camp_id, filename, extracols):
  160. urlstr = "/ocall/campapi"
  161. params = {
  162. 'action': 'exportcamp',
  163. 'camp_id_id': camp_id,
  164. 'f': filename,
  165. 'extracols': extracols
  166. }
  167. res = self.postToGateway(urlstr, params)
  168. return ast.literal_eval(res)