@nyaruka/temba-components 0.138.4 → 0.138.6

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.138.6](https://github.com/nyaruka/temba-components/compare/v0.138.4...v0.138.6)
8
+
9
+ - Add ticket permission controls to ContactChat [`#811`](https://github.com/nyaruka/temba-components/pull/811)
10
+
7
11
  #### [v0.138.4](https://github.com/nyaruka/temba-components/compare/v0.138.3...v0.138.4)
8
12
 
13
+ > 5 February 2026
14
+
9
15
  - Update build command to include yarn install [`a15d622`](https://github.com/nyaruka/temba-components/commit/a15d622a281171fe391b8bd3c2cd4e36f9cf2f9f)
10
16
 
11
17
  #### [v0.138.3](https://github.com/nyaruka/temba-components/compare/v0.138.2...v0.138.3)
@@ -3146,7 +3146,7 @@ const{I:oh}=at,sh=()=>document.createComment(""),rh=(t,e,i)=>{const n=t._$AA.par
3146
3146
  temba-button {
3147
3147
  --button-border: 1px solid #ddd;
3148
3148
  }
3149
- `}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=xl,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(Pn.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(Pn.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){const e=_h(t,!1);e&&(t._rendered={html:e,type:ph.Inline})}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;kh(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}kh(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>
3149
+ `}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.disableAssign=!1,this.disableReply=!1,this.avatar=xl,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(Pn.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(Pn.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){const e=_h(t,!1);e&&(t._rendered={html:e,type:ph.Inline})}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;kh(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}kh(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.disableReply||this.currentTicket.assignee&&this.currentTicket.assignee.email===this.agent?this.getCompose():null:this.currentContact&&"active"!==this.currentContact.status?null:this.getCompose()}getCompose(){return V`<div class="border"></div>
3150
3150
  <div class="compose">
3151
3151
  <temba-compose
3152
3152
  attachments
@@ -3164,7 +3164,7 @@ const{I:oh}=at,sh=()=>document.createComment(""),rh=(t,e,i)=>{const n=t._$AA.par
3164
3164
  @click=${this.handleRetry}
3165
3165
  ></temba-button>
3166
3166
  </div>`:null}
3167
- </div>`}handleAssignmentChanged(t){const e=t.currentTarget,i=e.values[0];this.assignTicket(i?i.email:null),e.blur()}handleTopicChanged(t){const e=t.target.values[0];this.currentTicket.topic.uuid!==e.uuid&&pe("/api/v2/ticket_actions.json",{tickets:[this.currentTicket.uuid],action:"change_topic",topic:e.uuid}).then((()=>{this.refreshTicket()})).catch((t=>{console.error(t)}))}assignTicket(t){if(!(this.currentTicket.assignee&&this.currentTicket.assignee.email===t||null===this.currentTicket.assignee&&null===t))return pe("/api/v2/ticket_actions.json",{tickets:[this.currentTicket.uuid],action:"assign",assignee:t}).then((()=>{this.refreshTicket()})).catch((t=>{console.error(t)})),!0}refreshTicket(){this.currentTicket&&ce(`/api/v2/tickets.json?uuid=${this.currentTicket.uuid}`).then((t=>{t.length>0&&(this.fireCustomEvent(Pn.TicketUpdated,{ticket:t[0],previous:this.currentTicket}),this.currentTicket=t[0])}))}handleReopen(){const t=this.currentTicket.uuid;pe("/api/v2/ticket_actions.json",{tickets:[t],action:"reopen"}).then((()=>{this.refreshTicket()})).catch((t=>{console.error(t)}))}handleClose(){const t=this.currentTicket.uuid;pe("/api/v2/ticket_actions.json",{tickets:[t],action:"close"}).then((()=>{this.refreshTicket()})).catch((t=>{console.error(t)}))}render(){const t=this.currentContact&&this.currentContact.flow,e=this.currentTicket,i=this.currentTicket&&this.currentTicket.closed_on;return V`<div class="chat-wrapper">
3167
+ </div>`}handleAssignmentChanged(t){const e=t.currentTarget,i=e.values[0];this.assignTicket(i?i.email:null),e.blur()}handleTopicChanged(t){const e=t.target.values[0];this.currentTicket.topic.uuid!==e.uuid&&pe("/api/v2/ticket_actions.json",{tickets:[this.currentTicket.uuid],action:"change_topic",topic:e.uuid}).then((()=>{this.refreshTicket()})).catch((t=>{console.error(t)}))}assignTicket(t){if(!this.disableAssign&&!(this.currentTicket.assignee&&this.currentTicket.assignee.email===t||null===this.currentTicket.assignee&&null===t))return pe("/api/v2/ticket_actions.json",{tickets:[this.currentTicket.uuid],action:"assign",assignee:t}).then((()=>{this.refreshTicket()})).catch((t=>{console.error(t)})),!0}refreshTicket(){this.currentTicket&&ce(`/api/v2/tickets.json?uuid=${this.currentTicket.uuid}`).then((t=>{t.length>0&&(this.fireCustomEvent(Pn.TicketUpdated,{ticket:t[0],previous:this.currentTicket}),this.currentTicket=t[0])}))}handleReopen(){const t=this.currentTicket.uuid;pe("/api/v2/ticket_actions.json",{tickets:[t],action:"reopen"}).then((()=>{this.refreshTicket()})).catch((t=>{console.error(t)}))}handleClose(){const t=this.currentTicket.uuid;pe("/api/v2/ticket_actions.json",{tickets:[t],action:"close"}).then((()=>{this.refreshTicket()})).catch((t=>{console.error(t)}))}render(){const t=this.currentContact&&this.currentContact.flow,e=this.currentTicket,i=this.currentTicket&&this.currentTicket.closed_on;return V`<div class="chat-wrapper">
3168
3168
  ${this.currentContact?V`<temba-chat
3169
3169
  @temba-scroll-threshold=${this.fetchPreviousMessages}
3170
3170
  @temba-fetch-complete=${this.fetchComplete}
@@ -3209,7 +3209,7 @@ const{I:oh}=at,sh=()=>document.createComment(""),rh=(t,e,i)=>{const n=t._$AA.par
3209
3209
  clearable
3210
3210
  .values=${this.currentTicket.assignee?[this.currentTicket.assignee]:[]}
3211
3211
  @change=${this.handleAssignmentChanged}
3212
- ?disabled=${i}
3212
+ ?disabled=${i||this.disableAssign}
3213
3213
  ></temba-user-select>
3214
3214
 
3215
3215
  <temba-select
@@ -3237,7 +3237,7 @@ const{I:oh}=at,sh=()=>document.createComment(""),rh=(t,e,i)=>{const n=t._$AA.par
3237
3237
  </div>
3238
3238
  </div> `:null}
3239
3239
  ${this.getTembaCompose()}`:null}
3240
- </div>`}}t([mt({type:String,attribute:"ticket"})],wh.prototype,"ticketUUID",void 0),t([mt({type:String})],wh.prototype,"contactsEndpoint",void 0),t([mt({type:String})],wh.prototype,"currentNote",void 0),t([mt({type:Boolean})],wh.prototype,"showDetails",void 0),t([mt({type:Object})],wh.prototype,"currentTicket",void 0),t([mt({type:Object})],wh.prototype,"currentContact",void 0),t([mt({type:String})],wh.prototype,"agent",void 0),t([mt({type:Boolean})],wh.prototype,"blockFetching",void 0),t([mt({type:Boolean})],wh.prototype,"showInterrupt",void 0),t([mt({type:String})],wh.prototype,"avatar",void 0),t([mt({type:String})],wh.prototype,"showMessageLogsAfter",null),t([mt({type:String})],wh.prototype,"errorMessage",void 0);const kh=(t,e=void 0,i=void 0,n=void 0)=>new Promise((o=>{const s=new AbortController;Ch.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=>{Ch=Ch.filter((e=>t.controller===e)),o(t.json)})).catch((()=>{}))}));let Ch=[];class Sh extends Ne{static get styles(){return a`
3240
+ </div>`}}t([mt({type:String,attribute:"ticket"})],wh.prototype,"ticketUUID",void 0),t([mt({type:String})],wh.prototype,"contactsEndpoint",void 0),t([mt({type:String})],wh.prototype,"currentNote",void 0),t([mt({type:Boolean})],wh.prototype,"showDetails",void 0),t([mt({type:Object})],wh.prototype,"currentTicket",void 0),t([mt({type:Object})],wh.prototype,"currentContact",void 0),t([mt({type:String})],wh.prototype,"agent",void 0),t([mt({type:Boolean})],wh.prototype,"blockFetching",void 0),t([mt({type:Boolean})],wh.prototype,"showInterrupt",void 0),t([mt({type:Boolean})],wh.prototype,"disableAssign",void 0),t([mt({type:Boolean})],wh.prototype,"disableReply",void 0),t([mt({type:String})],wh.prototype,"avatar",void 0),t([mt({type:String})],wh.prototype,"showMessageLogsAfter",null),t([mt({type:String})],wh.prototype,"errorMessage",void 0);const kh=(t,e=void 0,i=void 0,n=void 0)=>new Promise((o=>{const s=new AbortController;Ch.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=>{Ch=Ch.filter((e=>t.controller===e)),o(t.json)})).catch((()=>{}))}));let Ch=[];class Sh extends Ne{static get styles(){return a`
3241
3241
  temba-options {
3242
3242
  display: block;
3243
3243
  width: 100%;