teamwire_api/attachments¶
AttachmentType¶
AttachmentType
CALENDAR¶
Calendar Attachment Type
LOCATION¶
Location Attachment Type
GALLERY¶
Gallery Attachment Type
SOUND¶
Sound Attachment Type
VIDEO¶
Video Attachment Type
FILE¶
File Attachment Type
POLL¶
Poll Attachment Type
LIVE_LOCATION¶
Live Location Attachment Type
Attachment¶
The base class for all kinds of attachments. This is never directly instantiated.
Attributes
type
:AttachmentType
. The type of attachment
CalendarAttachment¶
An attachment representing a calendar event This is never directly instantiated.
Attributes
title
: unicode. Title of the calendar eventstartDate
: datetime. The starting date of the eventendDate
: datetime. The ending date of the eventdescription
: unicode (optional). A textual description of the eventlocation
: unicode (optional). The location of the event
LocationAttachment¶
An attachment representing a geo location, or place This is never directly instantiated.
Attributes
name
: unicode. The name of the locationlat
: double between -90 and +90. The geo latitude of the locationlon
: double between 0 and 180. The geo longitude of the locationaddress
: unicode (optional). Address of the place (None if not available)city
: unicode (optional). City of the place (None if not available)country
: unicode (optional). Country of the place (None if not available)postalCode
: unicode (optional). Postal code of the place (None if not available)
LocationSharingDuration¶
LocationSharingDuration
DURATION_15_MIN¶
15 Minutes
DURATION_1_HR¶
1 Hour
DURATION_8_HR¶
8 Hours
LocationSharingAttachment¶
An attachment for sharing an updated live location This is never directly instantiated.
Attributes
initial_lat
: double between -90 and +90. The geo latitude of the initial locationinitial_lon
: double between 0 and 180. The geo longitude of the initial locationduration
: integer. Number of seconds during which the sharing is active. The duration value must be one of theLocationSharingDuration
constants
get_updated_location¶
coroutine to load the last known state of this live-location
Returns
a LiveLocationUpdate structure containing up-to-date information about the shared location
Raises
exceptions.TWInvalidState
if the attachment has not been sent yet
exceptions.TWNotFoundError
if up-to-date information about the attachment cannot be found
exceptions.TWConnectionError
in case of network error or timeout
exceptions.TWServerError
in case of backend-related problems
PollChoice¶
A choice in a poll attachment
Attributes
text
: unicode. Choice textvotesCount
: integer. Number of votes received for this choice
PollData¶
Poll data
Attributes
createdAt
: datetime. Time of creation of the pollquestion
: unicode. The question asked in the pollchoices
: list ofPollChoice
objectsduration
: double. Duration of the poll in seconds (if 0 the poll is unlimited)ended
: boolean. Whether the poll has ended
PollAttachment¶
An attachment representing a poll This is never directly instantiated.
Attributes
canEnd
: boolean. Whether the poll can be ended by the bot
getPollData¶
coroutine to load the current state of a poll
Returns
a PollData
structure containing information about the poll
Raises
exceptions.TWPollLoadException
if the current poll data cannot be loaded
exceptions.TWConnectionError
in case of network error or timeout
exceptions.TWServerError
in case of backend-related problems
AssetAttachment¶
A generic attachment representing a binary asset (image, video, sound, file)
This is a base class for concrete asset attachments (e.g. SoundAttachment, VideoAttachment, GalleryAttachment, FileAttachment) and it's never instantiated explicitly.
Attributes
type
:AttachmentType
. The type of attachment
load¶
Coroutine that loads the content of an asset attachment
Returns
The binary content of the asset as byte array
Raises
exceptions.TWAssetLoadException
if the asset data cannot be loaded
exceptions.TWConnectionError
in case of network error or timeout
exceptions.TWServerError
in case of backend-related problems
store¶
Coroutine to store the asset attachmentâs content into the provided destination file
Arguments
- dest_file: unicode. The absolute path of the file where to store the content of the binary asset
GalleryAttachment¶
A gallery attachment
SoundAttachment¶
A sound attachment
VideoAttachment¶
A video attachment
FileInfo¶
File Attachment Information
Attributes
filename
: unicode. The name (name.ext) of the fileext
: unicode. The extension of the filesize
: integer. The size in bytes of the file
FileAttachment¶
A file attachment
Attributes
file_info
:FileInfo
. Information about the attached file
Attachments¶
Attachments container.
This is never directly instantiated. The Chat.new_attachments()
method
should be used instead.
Example
attachments = chat.new_attachments()
# add a file attachment
attachments.add_file('path/to/file.txt')
# send the attachment(s)
chat.post(attachments=attachments)
add_attachment¶
coroutine to add an attachment object (i.e. any of CalendarAttachment
, LocationAttachment
, GalleryAttachment
, SoundAttachment
, VideoAttachment
, FileAttachment
, PollAttachment
)
Note
for Asset-based and poll attachments, this method first performs an upload operation, which can fail with an exception, as detailed below.
Arguments
- attachment: an Attachment object. Since Attachment objects cannot be instantiated directly, this can be an item of the attachments list received with a message. Indeed, this method can be used to forward a received attachment to the same or to another chat.
Raises
exceptions.TWAttachmentNotAllowed
if sending the specific type of attachment (or attachments in general) is not allowed by the backend admin
exceptions.TWAssetUploadException
if an asset attachment cannot be uploaded
exceptions.TWPollCreationException
if a poll attachment cannot be created
exceptions.TWConnectionError
in case of network error or timeout
exceptions.TWServerError
in case of backend-related problems
add_file¶
coroutine to add a file attachment
Arguments
- file_name: unicode. The full path of the file to be attached
- data: bytes. If set, the data argument should contain the binary content of the file attachment, while file_name will be used to extract the basename of the file
Raises
exceptions.TWAttachmentNotAllowed
if sending the specific type of attachment (or attachments in general) is not allowed by the backend admin
exceptions.TWAssetUploadException
if the file cannot be uploaded
exceptions.TWConnectionError
in case of network error or timeout
exceptions.TWServerError
in case of backend-related problems
add_gallery_file¶
coroutine to add a gallery attachment from a file (deprecated since v1.3)
Arguments
- file_name: unicode. The full path of the file to be attached
Raises
exceptions.TWAttachmentNotAllowed
if sending the specific type of attachment (or attachments in general) is not allowed by the backend admin
exceptions.TWAssetUploadException
if the image file cannot be uploaded
exceptions.TWConnectionError
in case of network error or timeout
exceptions.TWServerError
in case of backend-related problems
add_gallery¶
coroutine to add a gallery attachment One between file_name and data arguments is required.
Arguments
- media: either string or bytes. If media is a string it will be interpreted as the full path of the file to be attached, otherwise it is interpreted as the binary content of the media file
Raises
exceptions.TWAttachmentNotAllowed
if sending the specific type of attachment (or attachments in general) is not allowed by the backend admin
exceptions.TWAssetUploadException
if the image file cannot be uploaded
exceptions.TWConnectionError
in case of network error or timeout
exceptions.TWServerError
in case of backend-related problems
add_sound_file¶
coroutine to add a sound attachment (deprecated since v1.3)
Arguments
- file_name: unicode. The full path of the file to be attached
Raises
exceptions.TWAttachmentNotAllowed
if sending the specific type of attachment (or attachments in general) is not allowed by the backend admin
exceptions.TWAssetUploadException
if the sound file cannot be uploaded
exceptions.TWConnectionError
in case of network error or timeout
exceptions.TWServerError
in case of backend-related problems
add_sound¶
coroutine to add a sound attachment
Arguments
- media: either string or bytes. If media is a string it will be interpreted as the full path of the file to be attached, otherwise it is interpreted as the binary content of the media file
Raises
exceptions.TWAttachmentNotAllowed
if sending the specific type of attachment (or attachments in general) is not allowed by the backend admin
exceptions.TWAssetUploadException
if the sound file cannot be uploaded
exceptions.TWConnectionError
in case of network error or timeout
exceptions.TWServerError
in case of backend-related problems
add_video_file¶
coroutine to add a video attachment (deprecated since v1.3)
Arguments
- file_name: unicode. The full path of the file to be attached
Raises
exceptions.TWAttachmentNotAllowed
if sending the specific type of attachment (or attachments in general) is not allowed by the backend admin
exceptions.TWAssetUploadException
if the video file cannot be uploaded
exceptions.TWConnectionError
in case of network error or timeout
exceptions.TWServerError
in case of backend-related problems
add_video¶
coroutine to add a video attachment
Arguments
- media: either string or bytes. If media is a string it will be interpreted as the full path of the file to be attached, otherwise it is interpreted as the binary content of the media file
Raises
exceptions.TWAttachmentNotAllowed
if sending the specific type of attachment (or attachments in general) is not allowed by the backend admin
exceptions.TWAssetUploadException
if the video file cannot be uploaded
exceptions.TWConnectionError
in case of network error or timeout
exceptions.TWServerError
in case of backend-related problems
add_location¶
coroutine to add a location attachment
Arguments
- name: unicode. The name of the location
- lat: double between -90 and +90. The geo latitude of the location
- lon: double between 0 and 180. The geo longitude of the location
- address: unicode (optional). Address of the place (None if not available)
- city: unicode (optional). City of the place (None if not available)
- country: unicode (optional). Country of the place (None if not available)
- postalCode: unicode (optional). Postal code of the place (None if not available)
Raises
exceptions.TWAttachmentNotAllowed
if sending the specific type of attachment (or attachments in general) is not allowed by the backend admin
add_location_sharing¶
coroutine to add a location attachment
Arguments
- lat: double between -90 and +90. The geo latitude of the initial location
- lon: double between 0 and 180. The geo longitude of the initial location
- duration: integer. Number of seconds during which the sharing is active. The duration value must be one of the
LocationSharingDuration
constants
Raises
exceptions.TWAttachmentNotAllowed
if sending the specific type of attachment (or attachments in general) is not allowed by the backend admin
add_calendar¶
coroutine to add a calendar attachment
Arguments
- title: unicode. Title of the calendar event
- startDate: datetime. The starting date of the event
- endDate: datetime. The ending date of the event
- description: unicode (optional). A textual description of the event
- location: unicode (optional). The location of the event
Raises
exceptions.TWAttachmentNotAllowed
if sending the specific type of attachment (or attachments in general) is not allowed by the backend admin
add_poll¶
coroutine to add a poll attachment
Arguments
- question: unicode. The question asked in the poll
- choices: list of strings representing the choice titles
- duration: double. Duration of the poll in seconds (if None the poll is unlimited)
Raises
exceptions.TWAttachmentNotAllowed
if sending the specific type of attachment (or attachments in general) is not allowed by the backend admin
exceptions.TWPollCreationException
if the poll attachment cannot be created
exceptions.TWConnectionError
in case of network error or timeout
exceptions.TWServerError
in case of backend-related problems