Skip to content

botcity.plugins.twilio.whatsapp.plugin.BotTwilioWhatsappPlugin

whatsapp_number: str property writable

The Whatsapp number that will be used to send messages.

__init__(self, account_sid, auth_token, whatsapp_number) special

BotTwilioWhatsapp.

Parameters:

Name Type Description Default
account_sid str

The unique Account Sid of your Twilio account.

required
auth_token str

The unique Auth Token of your Twilio account.

required
whatsapp_number str

A number that is active on your Twilio account to be used for sending messages. The number must be informed in this format: [+][country code][phone number including area code]

required

download_media_file(self, msg, download_folder_path=None)

Download the media content from a message and save on disk.

Parameters:

Name Type Description Default
msg MessageInstance

The message that contains a media content.

required
download_folder_path str

The folder where the file will be saved. Defaults to the current working directory.

None

get_received_messages(self, from_number=None, before_date=None, after_date=None, on_date=None, limit=None)

Get all messages that were received by the configured Whatsapp number.

Parameters:

Name Type Description Default
from_number str

Filters messages that were received only from this number.

None
before_date datetime

Filters messages that were received before this specific date.

None
after_date datetime

Filters messages that were received after this specific date.

None
on_date datetime

Filters messages that were received on this specific date.

None
limit int

The maximum number of messages that will be returned.

None

Returns:

Type Description
List[MessageInstance]

The list containing the messages found.

get_sent_messages(self, to_number=None, before_date=None, after_date=None, on_date=None, limit=None)

Get all messages that were sent by the configured Whatsapp number.

Parameters:

Name Type Description Default
to_number str

Filters messages that were sent only to this number.

None
before_date datetime

Filters messages that were sent before this specific date.

None
after_date datetime

Filters messages that were sent after this specific date.

None
on_date datetime

Filters messages that were sent on this specific date.

None
limit int

The maximum number of messages that will be returned.

None

Returns:

Type Description
List[MessageInstance]

The list containing the messages found.

reply_message(self, msg, text_content, media_url=None)

Reply to a previously received message.

Parameters:

Name Type Description Default
msg MessageInstance

The message to reply.

required
text_content str

The body of the reply message.

required
media_url str

The URL of a media content that will be sent in the message.

None

send_message(self, to_number, msg_content, media_url=None)

Sends an message via Whatsapp to the specified number. The to_number must be informed in this format: [+][country code][phone number including area code]

Parameters:

Name Type Description Default
to_number str

The Whatsapp number that will receive the message.

required
msg_content str

The message body content.

required
media_url str

The URL of a media content that will be sent in the message.

None

wait_for_new_message(self, from_number=None, timeout=60)

Wait for a new message until a timeout.

Parameters:

Name Type Description Default
from_number str

Wait for a new message from this specific number. Defaults to any new message.

None
timeout int

The maximum waiting time (in seconds). Defaults to 60s.

60

Returns:

Type Description
MessageInstance

The new message received. None otherwise.