Advertisement
Altair200333

call analysis query

Aug 12th, 2024
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. [
  2. {
  3. $match: {
  4. createdAt: {
  5. $gte: ISODate("2024-08-05")
  6. }
  7. }
  8. },
  9. {
  10. $addFields: {
  11. tid: {
  12. $toObjectId: "$taskId"
  13. },
  14. cid: {
  15. $toObjectId: "$gptContentId"
  16. },
  17. uid: {
  18. $toObjectId: "$userId"
  19. }
  20. }
  21. },
  22. {
  23. $lookup: {
  24. from: "outreach_prospect_activities",
  25. localField: "tid",
  26. foreignField: "_id",
  27. as: "task"
  28. }
  29. },
  30. {
  31. $lookup: {
  32. from: "gpt3_content",
  33. localField: "cid",
  34. foreignField: "_id",
  35. as: "content"
  36. }
  37. },
  38. {
  39. $lookup: {
  40. from: "users",
  41. localField: "uid",
  42. foreignField: "_id",
  43. as: "user"
  44. }
  45. },
  46. {
  47. $addFields: {
  48. task: {
  49. $first: "$task"
  50. },
  51. content: {
  52. $first: "$content"
  53. },
  54. user: {
  55. $first: "$user"
  56. }
  57. }
  58. },
  59. {
  60. $addFields: {
  61. disposition: "$task.callDisposition",
  62. calledAt: "$task.calledAt",
  63. transcript: "$content.fields.transcript",
  64. aiText: "$content.openAIText",
  65. sequencer: "$user.email",
  66. answeredAt: "$task.answeredAt",
  67. bridgedAt: "$task.bridgedAt"
  68. }
  69. },
  70. {
  71. $addFields: {
  72. bridgeTime: {
  73. $dateDiff: {
  74. startDate: "$answeredAt",
  75. endDate: "$bridgedAt",
  76. unit: "millisecond"
  77. }
  78. }
  79. }
  80. },
  81. {
  82. $group: {
  83. _id: "$_id",
  84. isBridged: {
  85. $first: "$isBridged"
  86. },
  87. answeredAt: {
  88. $first: "$answeredAt"
  89. },
  90. bridgedAt: {
  91. $first: "$bridgedAt"
  92. },
  93. bridgeTime: {
  94. $first: "$bridgeTime"
  95. },
  96. isConnected: {
  97. $first: "$isConnected"
  98. },
  99. isFalsePositive: {
  100. $first: "$isFalsePositive"
  101. },
  102. isConversation: {
  103. $first: "$isConversation"
  104. },
  105. taskId: {
  106. $first: "$taskId"
  107. },
  108. callSid: {
  109. $first: "$callSid"
  110. },
  111. sequencer: {
  112. $first: "$sequencer"
  113. },
  114. disposition: {
  115. $first: "$disposition"
  116. },
  117. transcript: {
  118. $accumulator: {
  119. accumulateArgs: ["$transcript"],
  120. init: function () {
  121. return [];
  122. },
  123. accumulate: function (names, name) {
  124. return names.concat(name);
  125. },
  126. merge: function (names1, names2) {
  127. return names1.concat(names2);
  128. },
  129. finalize: function (names) {
  130. return names.join("\n");
  131. },
  132. lang: "js"
  133. }
  134. },
  135. aiText: {
  136. $first: "$aiText"
  137. }
  138. }
  139. }
  140. // {
  141. // $match: {
  142. // "task.callDisposition": "Call Failed"
  143. // }
  144. // }
  145. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement