@nyaruka/temba-components 0.130.3 → 0.130.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,8 +4,16 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ #### [v0.130.4](https://github.com/nyaruka/temba-components/compare/v0.130.3...v0.130.4)
8
+
9
+ - Fix rendering of `ivr_created` events [`#697`](https://github.com/nyaruka/temba-components/pull/697)
10
+ - Update chat history test with more realistic event data [`#696`](https://github.com/nyaruka/temba-components/pull/696)
11
+ - Fix rendering of ivr_created events in chat history [`261f082`](https://github.com/nyaruka/temba-components/commit/261f082a6d8fbdc2244a1e59fa07a49f33439c36)
12
+
7
13
  #### [v0.130.3](https://github.com/nyaruka/temba-components/compare/v0.130.2...v0.130.3)
8
14
 
15
+ > 23 September 2025
16
+
9
17
  - Remove support for legacy ticket events [`#694`](https://github.com/nyaruka/temba-components/pull/694)
10
18
 
11
19
  #### [v0.130.2](https://github.com/nyaruka/temba-components/compare/v0.130.1...v0.130.2)
@@ -3006,7 +3006,7 @@ let rl=ja,al=!1;const ll=["es","fr","pt"],cl="data:image/png;base64,iVBORw0KGgoA
3006
3006
  `}constructor(){super(),this.contactsEndpoint="/api/v2/contacts.json",this.currentNote="",this.showDetails=!0,this.currentTicket=null,this.currentContact=null,this.agent="",this.blockFetching=!1,this.showInterrupt=!1,this.avatar=cl,this.ticket=null,this.lastEventTime=null,this.newestEventTime=null,this.refreshId=null,this.polling=!1}firstUpdated(t){super.firstUpdated(t)}connectedCallback(){super.connectedCallback(),this.chat=this.shadowRoot.querySelector("temba-chat")}disconnectedCallback(){super.disconnectedCallback(),this.refreshId&&clearInterval(this.refreshId)}updated(t){super.updated(t),(t.has("data")||t.has("currentContact"))&&(this.refreshId&&(clearTimeout(this.refreshId),this.refreshId=null),this.currentContact=this.data),t.has("currentContact")&&(this.chat=this.shadowRoot.querySelector("temba-chat"),this.reset(),this.fetchPreviousMessages())}reset(){this.chat&&this.chat.reset(),this.blockFetching=!1,this.ticket=null,this.lastEventTime=null,this.newestEventTime=null,this.refreshId=null,this.polling=!1,this.errorMessage=null;const t=this.shadowRoot.querySelector("temba-compose");t&&t.reset()}handleInterrupt(){this.fireCustomEvent(xn.Interrupt,{contact:this.currentContact})}handleRetry(){this.shadowRoot.querySelector("temba-compose").triggerSend()}handleSend(t){this.errorMessage=null;const e=t.currentTarget,i=t.detail.langValues.und,n={contact:this.currentContact.uuid},o=i.text;o&&o.length>0&&(n.text=o);const s=i.attachments;if(s&&s.length>0){const t=s.map((t=>t.uuid));n.attachments=t}this.currentTicket&&(n.ticket=this.currentTicket.uuid);const r="Send failed, please try again.";le("/api/v2/messages.json",n).then((t=>{t.status<400?(this.checkForNewMessages(),e.reset(),this.fireCustomEvent(xn.MessageSent,{msg:n})):this.errorMessage=r})).catch((()=>{this.errorMessage=r}))}getEndpoint(){return this.contact?`/contact/history/${this.contact}/?_format=json`:null}scheduleRefresh(){let t=(new Date).getTime()-this.newestEventTime/1e3-5e3;this.refreshId&&(clearTimeout(this.refreshId),this.refreshId=null),t=Math.min(t,15e3),t=Math.max(t,2e3),this.refreshId=setTimeout((()=>{this.checkForNewMessages()}),t)}getEventMessage(t){let e=null;switch(t.type){case Xc.AIRTIME_TRANSFERRED:e={type:Wc.Inline,text:ah(t)};break;case Xc.CALL_CREATED:case Xc.CALL_MISSED:case Xc.CALL_RECEIVED:e={type:Wc.Inline,text:hh(t)};break;case Xc.CHAT_STARTED:e={type:Wc.Inline,text:th(t)};break;case Xc.CONTACT_FIELD_CHANGED:e={type:Wc.Inline,text:eh(t)};break;case Xc.CONTACT_GROUPS_CHANGED:e={type:Wc.Inline,text:rh(t)};break;case Xc.CONTACT_LANGUAGE_CHANGED:e={type:Wc.Inline,text:lh(t)};break;case Xc.CONTACT_NAME_CHANGED:e={type:Wc.Inline,text:ih(t)};break;case Xc.CONTACT_STATUS_CHANGED:e={type:Wc.Inline,text:ch(t)};break;case Xc.CONTACT_URNS_CHANGED:e={type:Wc.Inline,text:nh(t)};break;case Xc.OPTIN_REQUESTED:case Xc.OPTIN_STARTED:case Xc.OPTIN_STOPPED:e={type:Wc.Inline,text:dh(t)};break;case Xc.RUN_STARTED:case Xc.RUN_ENDED:e={type:Wc.Inline,text:Jc(t)};break;case Xc.TICKET_ASSIGNEE_CHANGED:e={type:Wc.Inline,text:sh(t)};break;case Xc.TICKET_CLOSED:e={type:Wc.Inline,text:oh(t,"closed")};break;case Xc.TICKET_OPENED:e={type:Wc.Inline,text:oh(t,"opened")};break;case Xc.TICKET_REOPENED:e={type:Wc.Inline,text:oh(t,"reopened")};break;case Xc.TICKET_TOPIC_CHANGED:e={type:Wc.Inline,text:U`<div>
3007
3007
  Topic changed to
3008
3008
  <strong>${t.topic.name}</strong>
3009
- </div>`};break;case Xc.CHANNEL_EVENT:e={type:Wc.Inline,text:Qc(t)}}return e&&t.created_on?e.date=new Date(t.created_on):console.error("Unknown event type",t),e.id||(e.id=t.uuid||t.type+"@"+t.created_on),e}getUserForEvent(t){return"msg_received"===t.type?{name:this.currentContact.name}:t._user?t._user:t.created_by?{email:t.created_by.email,name:`${t.created_by.first_name} ${t.created_by.last_name}`.trim(),avatar:t.created_by.avatar}:null}createMessages(t){if(t.events){let e=[];return t.events.forEach((t=>{const i=1e3*new Date(t.created_on).getTime();if(i>this.newestEventTime&&(this.newestEventTime=i),"ticket_note_added"===t.type){const i=t;e.push({type:Wc.Note,id:t.created_on+t.type,user:this.getUserForEvent(i),date:new Date(i.created_on),text:i.note})}else if("ticket_opened"===t.type){const i=t;e.push({type:Wc.Note,id:t.created_on+t.type+"_note",user:this.getUserForEvent(i),date:new Date(i.created_on),text:i.note}),e.push(this.getEventMessage(t))}else if("msg_created"===t.type||"msg_received"===t.type||"broadcast_created"===t.type){const i=t;e.push({id:t.uuid,type:"msg_received"===i.type?"msg_in":"msg_out",user:this.getUserForEvent(i),date:new Date(i.created_on),attachments:i.msg.attachments,text:i.msg.text,sendError:"E"===i.status||"F"===i.status,popup:U`<div
3009
+ </div>`};break;case Xc.CHANNEL_EVENT:e={type:Wc.Inline,text:Qc(t)};break;default:console.error("Unknown event type",t)}return e&&(e.id=t.uuid,e.date=new Date(t.created_on)),e}getUserForEvent(t){return"msg_received"===t.type?{name:this.currentContact.name}:t._user?t._user:t.created_by?{email:t.created_by.email,name:`${t.created_by.first_name} ${t.created_by.last_name}`.trim(),avatar:t.created_by.avatar}:null}createMessages(t){if(t.events){let e=[];return t.events.forEach((t=>{const i=1e3*new Date(t.created_on).getTime();if(i>this.newestEventTime&&(this.newestEventTime=i),"ticket_note_added"===t.type){const i=t;e.push({type:Wc.Note,id:t.created_on+t.type,user:this.getUserForEvent(i),date:new Date(i.created_on),text:i.note})}else if("ticket_opened"===t.type){const i=t;e.push({type:Wc.Note,id:t.created_on+t.type+"_note",user:this.getUserForEvent(i),date:new Date(i.created_on),text:i.note}),e.push(this.getEventMessage(t))}else if("msg_created"===t.type||"msg_received"===t.type||"ivr_created"===t.type||"broadcast_created"===t.type){const i=t;e.push({id:t.uuid,type:"msg_received"===i.type?"msg_in":"msg_out",user:this.getUserForEvent(i),date:new Date(i.created_on),attachments:i.msg.attachments,text:i.msg.text,sendError:"E"===i.status||"F"===i.status,popup:U`<div
3010
3010
  style="display: flex; flex-direction: row; align-items:center; justify-content: space-between;font-size:0.9em;line-height:1em;min-width:10em"
3011
3011
  >
3012
3012
  <div style="justify-content:left;text-align:left">
@@ -3029,7 +3029,7 @@ let rl=ja,al=!1;const ll=["es","fr","pt"],cl="data:image/png;base64,iVBORw0KGgoA
3029
3029
  ${i.logs_url?U`<a style="margin-left:0.5em" href="${i.logs_url}"
3030
3030
  ><temba-icon name="log"></temba-icon
3031
3031
  ></a>`:null}
3032
- </div> `})}else e.push(this.getEventMessage(t))})),e=e.filter((t=>!!t)),e}return[]}checkForNewMessages(){var t;if(this.polling)return;const e=this.chat,i=this;if(this.currentContact&&this.newestEventTime){this.polling=!0;const n=this.getEndpoint();if(!n)return;const o=this.currentContact.uuid;ph(!1,n,null===(t=this.currentTicket)||void 0===t?void 0:t.uuid,null,this.newestEventTime).then((t=>{if(o===this.currentContact.uuid){this.lastEventTime=t.next_before;const n=this.createMessages(t);0===n.length&&(i.blockFetching=!0),n.reverse(),e.addMessages(n,null,!0)}this.polling=!1,this.scheduleRefresh()}))}}fetchPreviousMessages(){var t;const e=this.chat,i=this;if(e&&!e.fetching&&!i.blockFetching&&(e.fetching=!0,this.currentContact)){const n=this.getEndpoint();if(!n)return;ph(!1,n,null===(t=this.currentTicket)||void 0===t?void 0:t.uuid,this.lastEventTime).then((t=>{this.lastEventTime=t.next_before;const n=this.createMessages(t);n.reverse(),0===n.length&&(i.blockFetching=!0),e.addMessages(n),this.scheduleRefresh()}))}}fetchComplete(){this.chat&&(this.chat.fetching=!1)}getTembaCompose(){return this.currentTicket?this.currentContact&&"active"!==this.currentContact.status||this.currentTicket.closed_on?null:this.getCompose():this.currentContact&&"active"!==this.currentContact.status?null:this.getCompose()}getCompose(){return U`<div class="border"></div>
3032
+ </div> `})}else{const i=this.getEventMessage(t);i&&e.push(i)}})),e=e.filter((t=>!!t)),e}return[]}checkForNewMessages(){var t;if(this.polling)return;const e=this.chat,i=this;if(this.currentContact&&this.newestEventTime){this.polling=!0;const n=this.getEndpoint();if(!n)return;const o=this.currentContact.uuid;ph(!1,n,null===(t=this.currentTicket)||void 0===t?void 0:t.uuid,null,this.newestEventTime).then((t=>{if(o===this.currentContact.uuid){this.lastEventTime=t.next_before;const n=this.createMessages(t);0===n.length&&(i.blockFetching=!0),n.reverse(),e.addMessages(n,null,!0)}this.polling=!1,this.scheduleRefresh()}))}}fetchPreviousMessages(){var t;const e=this.chat,i=this;if(e&&!e.fetching&&!i.blockFetching&&(e.fetching=!0,this.currentContact)){const n=this.getEndpoint();if(!n)return;ph(!1,n,null===(t=this.currentTicket)||void 0===t?void 0:t.uuid,this.lastEventTime).then((t=>{this.lastEventTime=t.next_before;const n=this.createMessages(t);n.reverse(),0===n.length&&(i.blockFetching=!0),e.addMessages(n),this.scheduleRefresh()}))}}fetchComplete(){this.chat&&(this.chat.fetching=!1)}getTembaCompose(){return this.currentTicket?this.currentContact&&"active"!==this.currentContact.status||this.currentTicket.closed_on?null:this.getCompose():this.currentContact&&"active"!==this.currentContact.status?null:this.getCompose()}getCompose(){return U`<div class="border"></div>
3033
3033
  <div class="compose">
3034
3034
  <temba-compose
3035
3035
  attachments