# Class: Attachment

## Constructor

#### new Attachment(thumbnailCreator)

  Attachments can be used to send files between Participants in existing Conversation.
  When created, it becomes a part of Message.

  Audio and video attachments should have thumbnails.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `thumbnailCreator` | AvayaClientServices.Services.Messaging.ThumbnailCreator |

## Methods

#### createThumbnail() → {AvayaClientServices.Base.Promise.<(AvayaClientServices.Services.Messaging.Attachment|String)>}

  If possible, creates a thumbnail for attachment.

  ##### See:

    - AvayaClientServices.Services.Messaging.Attachment#getThumbnail

  ##### Returns:

  { AvayaClientServices.Base.Promise.<(AvayaClientServices.Services.Messaging.Attachment|String)> }

#### getDownloadURL() → {String}

  Returns attachment URL.

  ##### Returns:

  { String }

#### getDuration() → {Number}

  Returns attachment duration in seconds. Applicable for audio/video files.

  ##### See:

    - AvayaClientServices.Services.Messaging.Attachment#setDuration

  ##### Returns:

  { Number }

#### getMimeType() → {String}

  Returns attachment MIME type.

  ##### See:

    - AvayaClientServices.Services.Messaging.Attachment#setMimeType

  ##### Returns:

  { String }

#### getName() → {String|undefined}

  Returns attachment name.

  ##### See:

    - AvayaClientServices.Services.Messaging.Attachment#setName

  ##### Returns:

  { String | undefined }

#### getSize() → {Number}

  Returns attachment size in bytes.

  ##### Returns:

  { Number }

#### getThumbnail() → {AvayaClientServices.Services.Messaging.Attachment|undefined}

  Returns attachment thumbnail if possible. If not, returns undefined.

  ##### See:

    - AvayaClientServices.Services.Messaging.Attachment#createThumbnail

  ##### Returns:

  { AvayaClientServices.Services.Messaging.Attachment | undefined }

#### removeThumbnail() → {void}

  Removes thumbnail from attachment.

  ##### See:

    - AvayaClientServices.Services.Messaging.Attachment#createThumbnail

  ##### Returns:

  { void }

#### setDuration(duration) → {void}

  Sets attachment duration in seconds. Applicable for audio/video files.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `duration` | Number | Value in seconds.

  ##### See:

    - AvayaClientServices.Services.Messaging.Attachment#getDuration

  ##### Returns:

  { void }

#### setMimeType(mimeType) → {void}

  Sets attachment MIME type.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `mimeType` | String | MIME type for attachment.

  ##### See:

    - AvayaClientServices.Services.Messaging.Attachment#getMimeType

  ##### Returns:

  { void }

#### setName(name) → {void}

  Sets attachment name.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `name` | String | Name for attachment.

  ##### See:

    - AvayaClientServices.Services.Messaging.Attachment#getName

  ##### Returns:

  { void }

### Managing callbacks

#### addOnHasThumbnailChangedCallback(callback) → {void}

  Adds new onHasThumbnailChangedCallback.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `callback` | AvayaClientServices.Services.Messaging.Attachment#onHasThumbnailChangedCallback |

  ##### Returns:

  { void }

#### addOnIsSelfGeneratedCallback(callback) → {void}

  Adds new onIsSelfGeneratedCallback.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `callback` | AvayaClientServices.Services.Messaging.Attachment#onIsSelfGeneratedCallback |

  ##### Returns:

  { void }

#### addOnStatusChangedCallback(callback) → {void}

  Adds new onStatusChangedCallback.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `callback` | AvayaClientServices.Services.Messaging.Attachment#onStatusChangedCallback |

  ##### Returns:

  { void }

#### removeOnHasThumbnailChangedCallback(callback) → {void}

  Removes existing onHasThumbnailChangedCallback.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `callback` | AvayaClientServices.Services.Messaging.Attachment#onHasThumbnailChangedCallback |

  ##### Returns:

  { void }

#### removeOnIsSelfGeneratedCallback(callback) → {void}

  Removes existing onIsSelfGeneratedCallback.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `callback` | AvayaClientServices.Services.Messaging.Attachment#onIsSelfGeneratedCallback |

  ##### Returns:

  { void }

#### removeOnStatusChangedCallback(callback) → {void}

  Removes existing onStatusChangedCallback.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `callback` | AvayaClientServices.Services.Messaging.Attachment#onStatusChangedCallback |

  ##### Returns:

  { void }

### Capabilities

#### getCreateThumbnailCapability() → {AvayaClientServices.Base.Capability}

  Gets capability to create a thumbnail for attachment.

           if (attachment MIME type is supported)
               allow
           else
               deny

  ##### Returns:

  { AvayaClientServices.Base.Capability }

#### getRemoveCapability() → {AvayaClientServices.Base.Capability}

  Returns Capability object that indicates if attachment can be removed.
  This capability is Allowed when Attachment is in a draft state.

           if (attachment is DRAFT_UNSENT)
               allow
           else
               deny

  ##### Returns:

  { AvayaClientServices.Base.Capability }

#### getRemoveThumbnailCapability() → {AvayaClientServices.Base.Capability}

  Returns Capability object that indicates if thumbnail can be removed from attachment.
  This capability is Allowed when Attachment is in a draft state.

           if (attachment is DRAFT_UNSENT)
               allow
           else
               deny

  ##### Returns:

  { AvayaClientServices.Base.Capability }

#### getUpdateDurationCapability() → {AvayaClientServices.Base.Capability}

  Returns Capability object that indicates if attachment duration property can be changed.
  This capability is Allowed when Attachment is in a draft state.

           if (attachment is DRAFT_UNSENT)
               allow
           else
               deny

  ##### Returns:

  { AvayaClientServices.Base.Capability }

#### getUpdateIsSelfGeneratedCapability() → {AvayaClientServices.Base.Capability}

  Returns Capability object that indicates if a thumbnail for attachment can be created.

  ##### Returns:

  { AvayaClientServices.Base.Capability }

#### getUpdateMimeTypeCapability() → {AvayaClientServices.Base.Capability}

  Returns Capability object that indicates if attachment MIME type property can be changed.
  This capability is Allowed when Attachment is in draft state.

           if (attachment is DRAFT_UNSENT)
               allow
           else
               deny

  ##### Returns:

  { AvayaClientServices.Base.Capability }

#### getUpdateNameCapability() → {AvayaClientServices.Base.Capability}

  Returns Capability object that indicates if attachment name property can be changed.
  This capability is Allowed when Attachment is in a draft state.

           if (attachment is DRAFT_UNSENT)
               allow
           else
               deny

  ##### Returns:

  { AvayaClientServices.Base.Capability }

## Type Definitions

#### onHasThumbnailChangedCallback(attachment, hasThumbnail) → {void}

  Interface for callback function to be invoked when attachment has a thumbnail created or removed.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `attachment` | AvayaClientServices.Services.Messaging.Attachment | Instance of attachment.
  `hasThumbnail` | boolean | True if an attachment now has a thumbnail. False otherwise.

  ##### Returns:

  { void }

#### onIsSelfGeneratedCallback(Attachment, isSelfGenerated) → {void}

  Interface for callback function to be invoked when attachment's isSelfGenerated flag changes.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `Attachment` | AvayaClientServices.Services.Messaging.Attachment | Instance of attachment.
  `isSelfGenerated` | boolean | New value of isSelfGenerated flag.

  ##### Returns:

  { void }

#### onStatusChangedCallback(attachment, resourceStatus) → {void}

  Interface for callback function to be invoked when attachment's resource status changes.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `attachment` | AvayaClientServices.Services.Messaging.Attachment | Instance of attachment.
  `resourceStatus` | string | New attachment's resource status.

  ##### Returns:

  { void }