teamwire_api.attachments¶
AttachmentType¶
class AttachmentType(enum.Enum)
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¶
class Attachment(object)
The base class for all kinds of attachments. This is never directly instantiated.
Attributes
type
:AttachmentType
. The type of attachment
CalendarAttachment¶
class CalendarAttachment(Attachment)
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¶
class LocationAttachment(Attachment)
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)
LocationSharingAttachment¶
class LocationSharingAttachment(Attachment)
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¶
| async 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¶
class PollChoice(object)
A choice in a poll attachment
Attributes
text
: unicode. Choice textvotesCount
: integer. Number of votes received for this choice
PollData¶
class PollData(object)
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¶
class PollAttachment(Attachment)
An attachment representing a poll This is never directly instantiated.
Attributes
canEnd
: boolean. Whether the poll can be ended by the bot
getPollData¶
| async 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¶
class AssetAttachment(Attachment)
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¶
| async 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¶
| async store(dest_file)
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¶
class GalleryAttachment(AssetAttachment)
A gallery attachment
SoundAttachment¶
class SoundAttachment(AssetAttachment)
A sound attachment
VideoAttachment¶
class VideoAttachment(AssetAttachment)
A video attachment
FileInfo¶
class FileInfo(object)
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¶
class FileAttachment(AssetAttachment)
A file attachment
Attributes
file_info
:FileInfo
. Information about the attached file
Attachments¶
class Attachments(object)
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¶
| async add_attachment(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. SinceAttachment
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¶
| async add_file(file_name, data=None)
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¶
| async add_gallery_file(file_name)
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¶
| async add_gallery(media)
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¶
| async add_sound_file(file_name)
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¶
| async add_sound(media)
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¶
| async add_video_file(file_name)
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¶
| async add_video(media)
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¶
| async add_location(name, lat, lon, address=None, city=None, country=None, postalCode=None)
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¶
| async add_location_sharing(lat, lon, duration)
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¶
| async add_calendar(title, startDate, endDate, description=None, location=None)
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¶
| async add_poll(question, choices, duration=None)
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