Announcement

Collapse
No announcement yet.

Copy Attachments from Stream

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Copy Attachments from Stream

    Hello,

    I have a custom entity for WhatsApp in my instance, whenever we receive a whatsapp message a new post gets created in the stream, if the message is a pdf/image that's what get posted.

    This entity has an ActionButton to create a Lead from the WhatsApp conversation if No lead is already present.

    I 'd like to copy all the attachments in the WhatsApp conversation stream to the lead Attachments field in Lead, would that be possibile?
    What's the best way to achieve that? a Hook? Adding the attributes to the handler??
    This is my current code.

    WhatsApp-handler.js
    Code:
    define('custom:WhatsApp-handler', ['action-handler'], function (Dep) {
    
       return Dep.extend({
    
          actionNewLead: function() {
            var attributes = {};
            attributes.phoneNumber = this.view.model.get('from');
            attributes.whatsAppId = this.view.model.get('id');
            attributes.whatsAppName = this.view.model.get('name');
            attributes.source = "WhatsApp";
            var scope = 'Lead'
            var router = this.getRouter();
            router.dispatch(scope, 'create', {
            attributes: attributes,
    
     });
     },
    
            initNewLead: function () {
                this.controlButtonVisibility();
    
                this.view.listenTo(
                    this.view.model,
                    'change:leadId',
                    this.controlButtonVisibility.bind(this)
                );
            },
    
            controlButtonVisibility: function () {
                if (this.view.model.get('leadId') === null) {
                    this.view.showHeaderActionItem('NewLead');
    
                    return;
                }
    
                this.view.hideHeaderActionItem('NewLead');
            },
       });
    });
    ​
    Last edited by Kharg; 09-10-2022, 06:40 PM.

  • #2
    The main thing is that copying just ids is not enough. You need to copy attachment records and set their sourceId = originalAttachmenent.sourseId ?? originalAttachmenent.id. There were a few topic on this here on the forum.

    Comment


    • #3
      Thanks Yuri.
      I kinda solved by posting the attachments to an Attachments field instead of the stream, even though these attachments gets moved to the new parent instead of duplicating.
      Wouldn't it be possible to enable the "foreign" field for Attachement Multiple fields as well? This would solve these kinds of problems easily, what do you think?
      Last edited by Kharg; 09-12-2022, 09:25 AM.

      Comment


      • #4
        > Wouldn't it be possible to enable the "foreign" field for Attachement Multiple fields as well?

        Not possible technically with the current approach.

        Comment


        • #5
          Hello, does anyone have an EspoCRM integration with Whatsapp?

          Comment

          Working...
          X