@nyaruka/temba-components 0.134.2 → 0.134.3

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,14 @@ 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.134.3](https://github.com/nyaruka/temba-components/compare/v0.134.2...v0.134.3)
8
+
9
+ - Fix handling of showMessageLogsAfter property in ContactChat component [`#771`](https://github.com/nyaruka/temba-components/pull/771)
10
+
7
11
  #### [v0.134.2](https://github.com/nyaruka/temba-components/compare/v0.134.1...v0.134.2)
8
12
 
13
+ > 1 December 2025
14
+
9
15
  - Generate message log URLs for messages [`#770`](https://github.com/nyaruka/temba-components/pull/770)
10
16
  - Generate message log URLs for messages created within a specified number of days. [`1e6433d`](https://github.com/nyaruka/temba-components/commit/1e6433dcaccf3a8cf1e07f5865eda16db7f16e70)
11
17
  - Use Date type property on Chat component [`cf244e1`](https://github.com/nyaruka/temba-components/commit/cf244e102fbb2aaa22eb688eeda9172270ddfb70)
@@ -3029,7 +3029,7 @@ const{I:th}=at,eh=()=>document.createComment(""),ih=(t,e,i)=>{const n=t._$AA.par
3029
3029
  temba-button {
3030
3030
  --button-border: 1px solid #ddd;
3031
3031
  }
3032
- `}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=yl,this.showMessageLogsAfter=null,this.ticket=null,this.beforeUUID=null,this.afterUUID=null,this.refreshId=null,this.polling=!1,this.pollingInterval=2e3,this.lastFetchTime=null}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){var e;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.currentContact&&(this.chat=this.shadowRoot.querySelector("temba-chat"),this.currentContact.uuid!==(null===(e=t.get("currentContact"))||void 0===e?void 0:e.uuid)?this.reset():setTimeout((()=>this.checkForNewMessages()),500),this.fetchPreviousMessages())}reset(){this.chat&&this.chat.reset(),this.blockFetching=!1,this.ticket=null,this.beforeUUID=null,this.afterUUID=null,this.refreshId=null,this.polling=!1,this.pollingInterval=2e3,this.lastFetchTime=null,this.errorMessage=null;const t=this.shadowRoot.querySelector("temba-compose");t&&t.reset()}handleInterrupt(){this.fireCustomEvent(Dn.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.";pe(`/contact/chat/${this.currentContact.uuid}/`,n).then((t=>{if(t.status<400){const i=t.json.event;i.created_on=new Date(i.created_on),this.chat.addMessages([i],null,!0),this.pollingInterval=2e3,this.checkForNewMessages(),e.reset(),this.fireCustomEvent(Dn.MessageSent,{msg:n,response:t})}else this.errorMessage=r})).catch((()=>{this.errorMessage=r}))}getEndpoint(){return this.contact?`/contact/chat/${this.contact}/`:null}scheduleRefresh(t=!1){this.refreshId&&(clearTimeout(this.refreshId),this.refreshId=null),this.pollingInterval=t?2e3:Math.min(this.pollingInterval+1e3,15e3),this.refreshId=setTimeout((()=>{this.checkForNewMessages()}),this.pollingInterval)}prerender(t){switch(t.type){case ph.AIRTIME_TRANSFERRED:t._rendered={html:kh(t),type:ch.Inline};break;case ph.CALL_CREATED:case ph.CALL_MISSED:case ph.CALL_RECEIVED:t._rendered={html:Eh(t),type:ch.Inline};break;case ph.CHAT_STARTED:t._rendered={html:fh(t),type:ch.Inline};break;case ph.CONTACT_FIELD_CHANGED:t._rendered={html:vh(t),type:ch.Inline};break;case ph.CONTACT_GROUPS_CHANGED:t._rendered={html:wh(t),type:ch.Inline};break;case ph.CONTACT_LANGUAGE_CHANGED:t._rendered={html:Ch(t),type:ch.Inline};break;case ph.CONTACT_NAME_CHANGED:t._rendered={html:yh(t),type:ch.Inline};break;case ph.CONTACT_STATUS_CHANGED:t._rendered={html:Sh(t),type:ch.Inline};break;case ph.CONTACT_URNS_CHANGED:t._rendered={html:bh(t),type:ch.Inline};break;case ph.OPTIN_REQUESTED:case ph.OPTIN_STARTED:case ph.OPTIN_STOPPED:t._rendered={html:Ah(t),type:ch.Inline};break;case ph.RUN_STARTED:case ph.RUN_ENDED:t._rendered={html:gh(t),type:ch.Inline};break;case ph.TICKET_ASSIGNEE_CHANGED:t._rendered={html:_h(t),type:ch.Inline};break;case ph.TICKET_CLOSED:t._rendered={html:xh(t,"closed"),type:ch.Inline};break;case ph.TICKET_OPENED:t._rendered={html:xh(t,"opened"),type:ch.Inline};break;case ph.TICKET_NOTE_ADDED:t._rendered={html:xh(t,"noted"),type:ch.Inline};break;case ph.TICKET_REOPENED:t._rendered={html:xh(t,"reopened"),type:ch.Inline};break;case ph.TICKET_TOPIC_CHANGED:t._rendered={html:V`<div>
3032
+ `}set showMessageLogsAfter(t){const e=this._showMessageLogsAfter;this._showMessageLogsAfter=t?new Date(t):null,this.requestUpdate("showMessageLogsAfter",e)}get showMessageLogsAfter(){return this._showMessageLogsAfter}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=yl,this._showMessageLogsAfter=null,this.ticket=null,this.beforeUUID=null,this.afterUUID=null,this.refreshId=null,this.polling=!1,this.pollingInterval=2e3,this.lastFetchTime=null}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){var e;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.currentContact&&(this.chat=this.shadowRoot.querySelector("temba-chat"),this.currentContact.uuid!==(null===(e=t.get("currentContact"))||void 0===e?void 0:e.uuid)?this.reset():setTimeout((()=>this.checkForNewMessages()),500),this.fetchPreviousMessages())}reset(){this.chat&&this.chat.reset(),this.blockFetching=!1,this.ticket=null,this.beforeUUID=null,this.afterUUID=null,this.refreshId=null,this.polling=!1,this.pollingInterval=2e3,this.lastFetchTime=null,this.errorMessage=null;const t=this.shadowRoot.querySelector("temba-compose");t&&t.reset()}handleInterrupt(){this.fireCustomEvent(Dn.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.";pe(`/contact/chat/${this.currentContact.uuid}/`,n).then((t=>{if(t.status<400){const i=t.json.event;i.created_on=new Date(i.created_on),this.chat.addMessages([i],null,!0),this.pollingInterval=2e3,this.checkForNewMessages(),e.reset(),this.fireCustomEvent(Dn.MessageSent,{msg:n,response:t})}else this.errorMessage=r})).catch((()=>{this.errorMessage=r}))}getEndpoint(){return this.contact?`/contact/chat/${this.contact}/`:null}scheduleRefresh(t=!1){this.refreshId&&(clearTimeout(this.refreshId),this.refreshId=null),this.pollingInterval=t?2e3:Math.min(this.pollingInterval+1e3,15e3),this.refreshId=setTimeout((()=>{this.checkForNewMessages()}),this.pollingInterval)}prerender(t){switch(t.type){case ph.AIRTIME_TRANSFERRED:t._rendered={html:kh(t),type:ch.Inline};break;case ph.CALL_CREATED:case ph.CALL_MISSED:case ph.CALL_RECEIVED:t._rendered={html:Eh(t),type:ch.Inline};break;case ph.CHAT_STARTED:t._rendered={html:fh(t),type:ch.Inline};break;case ph.CONTACT_FIELD_CHANGED:t._rendered={html:vh(t),type:ch.Inline};break;case ph.CONTACT_GROUPS_CHANGED:t._rendered={html:wh(t),type:ch.Inline};break;case ph.CONTACT_LANGUAGE_CHANGED:t._rendered={html:Ch(t),type:ch.Inline};break;case ph.CONTACT_NAME_CHANGED:t._rendered={html:yh(t),type:ch.Inline};break;case ph.CONTACT_STATUS_CHANGED:t._rendered={html:Sh(t),type:ch.Inline};break;case ph.CONTACT_URNS_CHANGED:t._rendered={html:bh(t),type:ch.Inline};break;case ph.OPTIN_REQUESTED:case ph.OPTIN_STARTED:case ph.OPTIN_STOPPED:t._rendered={html:Ah(t),type:ch.Inline};break;case ph.RUN_STARTED:case ph.RUN_ENDED:t._rendered={html:gh(t),type:ch.Inline};break;case ph.TICKET_ASSIGNEE_CHANGED:t._rendered={html:_h(t),type:ch.Inline};break;case ph.TICKET_CLOSED:t._rendered={html:xh(t,"closed"),type:ch.Inline};break;case ph.TICKET_OPENED:t._rendered={html:xh(t,"opened"),type:ch.Inline};break;case ph.TICKET_NOTE_ADDED:t._rendered={html:xh(t,"noted"),type:ch.Inline};break;case ph.TICKET_REOPENED:t._rendered={html:xh(t,"reopened"),type:ch.Inline};break;case ph.TICKET_TOPIC_CHANGED:t._rendered={html:V`<div>
3033
3033
  Topic changed to
3034
3034
  <strong>${t.topic.name}</strong>
3035
3035
  </div>`,type:ch.Inline};break;default:console.error("Unknown event type",t)}}createMessages(t){if(t.events){const e=[];return t.events.forEach((t=>{(!this.afterUUID||t.uuid.toLowerCase()>this.afterUUID.toLowerCase())&&(this.afterUUID=t.uuid),t.created_on=new Date(t.created_on),"msg_created"===t.type||"msg_received"===t.type||"ivr_created"===t.type?e.push(t):(this.prerender(t),t._rendered&&e.push(t))})),e.filter((t=>!!t))}return[]}checkForNewMessages(){var t;if(this.polling)return;const e=this.chat;if(this.currentContact&&this.afterUUID){this.polling=!0,this.lastFetchTime=Date.now();const i=this.getEndpoint();if(!i)return;const n=this.currentContact.uuid;Dh(i,null===(t=this.currentTicket)||void 0===t?void 0:t.uuid,null,this.afterUUID).then((t=>{const i=this.createMessages(t);if(i.reverse(),n===this.currentContact.uuid){const t=i.length>0;e.addMessages(i,null,!0),this.polling=!1,this.scheduleRefresh(t)}else this.polling=!1}))}}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;if(!this.beforeUUID&&!this.afterUUID){const t=Jt();this.beforeUUID=t,this.afterUUID=t}Dh(n,null===(t=this.currentTicket)||void 0===t?void 0:t.uuid,this.beforeUUID,null).then((t=>{const n=this.createMessages(t);if(n.reverse(),0===n.length)i.blockFetching=!0;else if(t.next)this.beforeUUID=t.next;else if(i.blockFetching=!0,t.events&&t.events.length>0){const i=t.events[t.events.length-1];e.setEndOfHistory(new Date(i.created_on))}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 V`<div class="border"></div>
@@ -3057,7 +3057,7 @@ const{I:th}=at,eh=()=>document.createComment(""),ih=(t,e,i)=>{const n=t._$AA.par
3057
3057
  avatar=${this.avatar}
3058
3058
  agent
3059
3059
  ?hasFooter=${t}
3060
- showMessageLogsAfter=${this.showMessageLogsAfter?new Date(this.showMessageLogsAfter):null}
3060
+ .showMessageLogsAfter=${this.showMessageLogsAfter}
3061
3061
  >
3062
3062
  ${t?V`
3063
3063
  <div slot="footer" style="text-align:center;">
@@ -3122,7 +3122,7 @@ const{I:th}=at,eh=()=>document.createComment(""),ih=(t,e,i)=>{const n=t._$AA.par
3122
3122
  </div>
3123
3123
  </div> `:null}
3124
3124
  ${this.getTembaCompose()}`:null}
3125
- </div>`}}t([mt({type:String,attribute:"ticket"})],Th.prototype,"ticketUUID",void 0),t([mt({type:String})],Th.prototype,"contactsEndpoint",void 0),t([mt({type:String})],Th.prototype,"currentNote",void 0),t([mt({type:Boolean})],Th.prototype,"showDetails",void 0),t([mt({type:Object})],Th.prototype,"currentTicket",void 0),t([mt({type:Object})],Th.prototype,"currentContact",void 0),t([mt({type:String})],Th.prototype,"agent",void 0),t([mt({type:Boolean})],Th.prototype,"blockFetching",void 0),t([mt({type:Boolean})],Th.prototype,"showInterrupt",void 0),t([mt({type:String})],Th.prototype,"avatar",void 0),t([mt({type:String})],Th.prototype,"showMessageLogsAfter",void 0),t([mt({type:String})],Th.prototype,"errorMessage",void 0);const Dh=(t,e=void 0,i=void 0,n=void 0)=>new Promise((o=>{const s=new AbortController;Mh.push(s);let r=t;const a=[];i&&a.push(`before=${i}`),n&&a.push(`after=${n}`),e&&a.push(`ticket=${e}`),a.length>0&&(r+=(r.includes("?")?"&":"?")+a.join("&")),re(r,s).then((t=>{Mh=Mh.filter((e=>t.controller===e)),o(t.json)})).catch((()=>{}))}));let Mh=[];class Ph extends ze{static get styles(){return a`
3125
+ </div>`}}t([mt({type:String,attribute:"ticket"})],Th.prototype,"ticketUUID",void 0),t([mt({type:String})],Th.prototype,"contactsEndpoint",void 0),t([mt({type:String})],Th.prototype,"currentNote",void 0),t([mt({type:Boolean})],Th.prototype,"showDetails",void 0),t([mt({type:Object})],Th.prototype,"currentTicket",void 0),t([mt({type:Object})],Th.prototype,"currentContact",void 0),t([mt({type:String})],Th.prototype,"agent",void 0),t([mt({type:Boolean})],Th.prototype,"blockFetching",void 0),t([mt({type:Boolean})],Th.prototype,"showInterrupt",void 0),t([mt({type:String})],Th.prototype,"avatar",void 0),t([mt({type:String})],Th.prototype,"showMessageLogsAfter",null),t([mt({type:String})],Th.prototype,"errorMessage",void 0);const Dh=(t,e=void 0,i=void 0,n=void 0)=>new Promise((o=>{const s=new AbortController;Mh.push(s);let r=t;const a=[];i&&a.push(`before=${i}`),n&&a.push(`after=${n}`),e&&a.push(`ticket=${e}`),a.length>0&&(r+=(r.includes("?")?"&":"?")+a.join("&")),re(r,s).then((t=>{Mh=Mh.filter((e=>t.controller===e)),o(t.json)})).catch((()=>{}))}));let Mh=[];class Ph extends ze{static get styles(){return a`
3126
3126
  temba-options {
3127
3127
  display: block;
3128
3128
  width: 100%;