@nyaruka/temba-components 0.92.0 → 0.93.0
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.93.0](https://github.com/nyaruka/temba-components/compare/v0.92.0...v0.93.0)
|
|
8
|
+
|
|
9
|
+
- Support broadcast events, ignore unknown events [`99c2a40`](https://github.com/nyaruka/temba-components/commit/99c2a407539e4116bbf4c15b491ba11e71d65b8d)
|
|
10
|
+
|
|
7
11
|
#### [v0.92.0](https://github.com/nyaruka/temba-components/compare/v0.91.6...v0.92.0)
|
|
8
12
|
|
|
13
|
+
> 20 June 2024
|
|
14
|
+
|
|
9
15
|
- Use same chat for contact chat and web chat [`#436`](https://github.com/nyaruka/temba-components/pull/436)
|
|
10
16
|
- Add contact events [`3e6c153`](https://github.com/nyaruka/temba-components/commit/3e6c153b5a781af3d5fd8884796b2a5545da45c2)
|
|
11
17
|
- WIP. Merge contact history and webchat rendering [`a3e6e2e`](https://github.com/nyaruka/temba-components/commit/a3e6e2ef1d013bcb253b7d76bc3868bdf247b7e9)
|
package/dist/temba-components.js
CHANGED
|
@@ -2397,7 +2397,7 @@ let ir=Is,or=!1;const nr=["es","fr","pt"],{setLocale:sr}=(t=>(function(t){if(or)
|
|
|
2397
2397
|
}
|
|
2398
2398
|
`}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.avatar=yl,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(){this.refreshId&&clearInterval(this.refreshId)}updated(t){super.updated(t),(t.has("data")||t.has("currentContact"))&&(this.currentContact=this.data),t.has("currentContact")&&(this.chat=this.shadowRoot.querySelector("temba-chat"),this.reset(),this.fetchPreviousMessages())}reset(){this.blockFetching=!1,this.ticket=null,this.lastEventTime=null,this.newestEventTime=null,this.refreshId=null,this.polling=!1}refresh(){this.checkForNewMessages()}handleSend(t){const e=t.detail.name;if("Send"===e){const i={contact:this.currentContact.uuid},o=t.currentTarget;if(o){const t=o.currentText;t&&t.length>0&&(i.text=t);const e=o.currentAttachments;if(e&&e.length>0){const t=e.map((t=>t.uuid));i.attachments=t}}this.currentTicket&&(i.ticket=this.currentTicket.uuid);const n=e+" failed, please try again.";Kt("/api/v2/messages.json",i).then((t=>{if(t.status<400)this.checkForNewMessages(),o.reset(),this.fireCustomEvent(Me.MessageSent,{msg:i});else if(t.status<500)if(t.json.text&&t.json.text.length>0&&t.json.text[0].length>0){let e=t.json.text[0];e=e.replace("Ensure this field has no more than","Maximum allowed text is"),o.buttonError=e}else if(t.json.attachments&&t.json.attachments.length>0&&t.json.attachments[0].length>0){let e=t.json.attachments[0];e=e.replace("Ensure this field has no more than","Maximum allowed attachments is").replace("elements","files"),o.buttonError=e}else o.buttonError=n;else o.buttonError=n})).catch((t=>{console.error(t),o.buttonError=n}))}}render(){const t=this.currentContact?this.getTembaContactHistory():null,e=this.currentContact?this.getTembaChatbox():null,i=j`
|
|
2399
2399
|
<div class="chat-wrapper">${t} ${e}</div>
|
|
2400
|
-
`;return j`${i}`}getEndpoint(){return`/contact/history/${this.currentContact.uuid}/?_format=json`}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 Sl.ERROR:case Sl.FAILURE:e={type:xl.Inline,text:`Error during flow: ${i=t.text,i.charAt(0).toUpperCase()+i.slice(1)}`};break;case Sl.TICKET_OPENED:e={type:xl.Inline,text:Dl(t,"opened")};break;case Sl.TICKET_ASSIGNED:e={type:xl.Inline,text:Nl(t)};break;case Sl.TICKET_REOPENED:e={type:xl.Inline,text:Dl(t,"reopened")};break;case Sl.TICKET_CLOSED:e={type:xl.Inline,text:Dl(t,"closed")};break;case Sl.FLOW_ENTERED:case Sl.FLOW_EXITED:e={type:xl.Inline,text:$l(t)};break;case Sl.RUN_RESULT_CHANGED:e={type:xl.Inline,text:Ol(t)};break;case Sl.CONTACT_FIELD_CHANGED:e={type:xl.Inline,text:Ml(t)};break;case Sl.CONTACT_NAME_CHANGED:e={type:xl.Inline,text:Ll(t)};break;case Sl.CONTACT_URNS_CHANGED:e={type:xl.Inline,text:zl(t)};break;case Sl.EMAIL_SENT:e={type:xl.Inline,text:Pl(t)};break;case Sl.INPUT_LABELS_ADDED:e={type:xl.Inline,text:Il(t)};break;case Sl.CONTACT_GROUPS_CHANGED:e={type:xl.Inline,text:Bl(t)};break;case Sl.WEBHOOK_CALLED:e={type:xl.Inline,text:ql(t)};break;case Sl.AIRTIME_TRANSFERRED:e={type:xl.Inline,text:Ul(t)};break;case Sl.CALL_STARTED:e={type:xl.Inline,text:"Call Started"};break;case Sl.CAMPAIGN_FIRED:e={type:xl.Inline,text:Rl(t)};break;case Sl.CHANNEL_EVENT:e={type:xl.Inline,text:Tl(t)};break;case Sl.CONTACT_LANGUAGE_CHANGED:e={type:xl.Inline,text:Fl(t)};break;case Sl.OPTIN_REQUESTED:e={type:xl.Inline,text:Zl(t)}}var i;return e.date=new Date(t.created_on),e}getUserForEvent(t){let e=null;if(t.created_by){const i=this.store.getUser(t.created_by.email);i&&(e={email:t.created_by.email,name:[i.first_name,i.last_name].join(" "),avatar:i.avatar})}else"msg_received"===t.type&&(e={name:this.currentContact.name});return e}createMessages(t){let e=t.events.map((t=>{const e=1e3*new Date(t.created_on).getTime();if(e>this.newestEventTime&&(this.newestEventTime=e),"ticket_note_added"===t.type){const e=t;return{type:xl.Note,id:t.created_on+t.type,user:this.getUserForEvent(e),date:new Date(e.created_on),text:e.note}}if("msg_created"===t.type||"msg_received"===t.type){const e=t;return{type:"
|
|
2400
|
+
`;return j`${i}`}getEndpoint(){return`/contact/history/${this.currentContact.uuid}/?_format=json`}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 Sl.ERROR:case Sl.FAILURE:e={type:xl.Inline,text:`Error during flow: ${i=t.text,i.charAt(0).toUpperCase()+i.slice(1)}`};break;case Sl.TICKET_OPENED:e={type:xl.Inline,text:Dl(t,"opened")};break;case Sl.TICKET_ASSIGNED:e={type:xl.Inline,text:Nl(t)};break;case Sl.TICKET_REOPENED:e={type:xl.Inline,text:Dl(t,"reopened")};break;case Sl.TICKET_CLOSED:e={type:xl.Inline,text:Dl(t,"closed")};break;case Sl.FLOW_ENTERED:case Sl.FLOW_EXITED:e={type:xl.Inline,text:$l(t)};break;case Sl.RUN_RESULT_CHANGED:e={type:xl.Inline,text:Ol(t)};break;case Sl.CONTACT_FIELD_CHANGED:e={type:xl.Inline,text:Ml(t)};break;case Sl.CONTACT_NAME_CHANGED:e={type:xl.Inline,text:Ll(t)};break;case Sl.CONTACT_URNS_CHANGED:e={type:xl.Inline,text:zl(t)};break;case Sl.EMAIL_SENT:e={type:xl.Inline,text:Pl(t)};break;case Sl.INPUT_LABELS_ADDED:e={type:xl.Inline,text:Il(t)};break;case Sl.CONTACT_GROUPS_CHANGED:e={type:xl.Inline,text:Bl(t)};break;case Sl.WEBHOOK_CALLED:e={type:xl.Inline,text:ql(t)};break;case Sl.AIRTIME_TRANSFERRED:e={type:xl.Inline,text:Ul(t)};break;case Sl.CALL_STARTED:e={type:xl.Inline,text:"Call Started"};break;case Sl.CAMPAIGN_FIRED:e={type:xl.Inline,text:Rl(t)};break;case Sl.CHANNEL_EVENT:e={type:xl.Inline,text:Tl(t)};break;case Sl.CONTACT_LANGUAGE_CHANGED:e={type:xl.Inline,text:Fl(t)};break;case Sl.OPTIN_REQUESTED:e={type:xl.Inline,text:Zl(t)}}var i;return e&&t.created_on?e.date=new Date(t.created_on):console.error("Unknown event type",t),e}getUserForEvent(t){let e=null;if(t.created_by){const i=this.store.getUser(t.created_by.email);i&&(e={email:t.created_by.email,name:[i.first_name,i.last_name].join(" "),avatar:i.avatar})}else"msg_received"===t.type&&(e={name:this.currentContact.name});return e}createMessages(t){let e=t.events.map((t=>{const e=1e3*new Date(t.created_on).getTime();if(e>this.newestEventTime&&(this.newestEventTime=e),"ticket_note_added"===t.type){const e=t;return{type:xl.Note,id:t.created_on+t.type,user:this.getUserForEvent(e),date:new Date(e.created_on),text:e.note}}if("msg_created"===t.type||"msg_received"===t.type||"broadcast_created"===t.type){const e=t;return{type:"msg_received"===e.type?"msg_in":"msg_out",id:e.msg.id+"",user:this.getUserForEvent(e),date:new Date(e.created_on),attachments:e.msg.attachments,text:e.msg.text,sendError:"E"===e.status||"F"===e.status,popup:j`<div
|
|
2401
2401
|
style="display: flex; flex-direction: row; align-items:center; justify-content: space-between;font-size:0.9em;line-height:1em;min-width:10em"
|
|
2402
2402
|
>
|
|
2403
2403
|
<div style="justify-content:left;text-align:left">
|
|
@@ -2406,6 +2406,9 @@ let ir=Is,or=!1;const nr=["es","fr","pt"],{setLocale:sr}=(t=>(function(t){if(or)
|
|
|
2406
2406
|
display="duration"
|
|
2407
2407
|
></temba-date>
|
|
2408
2408
|
|
|
2409
|
+
${e.optin?j`<div style="font-size:0.9em;color:#aaa">
|
|
2410
|
+
${e.optin.name}
|
|
2411
|
+
</div>`:null}
|
|
2409
2412
|
${e.failed_reason_display?j`
|
|
2410
2413
|
<div
|
|
2411
2414
|
style="margin-top:0.2em;margin-right: 0.5em;min-width:10em;max-width:15em;color:var(--color-error);font-size:0.9em"
|