TNAPI is a python module that uses TextNow to enable free programmable texting
- Developer: Leonardo Wu-Gomez
- Please tell me if you have any ideas for the API or reporting a bug
git clone https://github.com/WuGomezCode/TextNow-API.gitpip install PyTextNowNote: If there is an unexplained error with the pip install, try adding the --user flag to it.
import pytextnow
# Way 1. Include connect.sid and csrf cookie in the constructor
client = pytextnow.Client("username", sid_cookie="sid", csrf_cookie="csrf").
# Way 2. Just instantiate and a prompt will appear on the command line
# Way 3. If you inputed the wrong cookie and are getting RequestFailed. This is how to reset it
client.auth_reset()
# will redo the promptclient.send_sms("number", "Hello World!")file_path = "./img.jpeg"
client.send_mms("number", file_path)new_messages = client.get_unread_messages() -> MessageContainer list
for message in new_messages:
message.mark_as_read()
print(message)
# Class Message | Class MultiMediaMessage
# Message
# content: "body of sms"
# number: "number of sender"
# date: datetime object of when the message was received
# read: bool
# id: int
# direction: SENT_MESSAGE_TYPE or RECEIVED_MESSAGE_TYPE
# first_contact: bool if its the first time that number texted you
# type: MESSAGE_TYPE if class is Message and MULTIMEDIAMESSAGE_TYPE if class is MultiMediaMessage
# Functions
# mark_as_read() will post the server as read
# send_sms() will send an sms to the number who sent the message
# send_mms() will send an mms to the number who sent the message
# MultiMediaMessage
# All the attributes of Message
# content: url of media
# raw_data: bytes of the media
# content_type: str the MIME type ie. "image/jpeg" or "video/mp4"
# extension: str of the file extension is. "jpeg" or "mp4"
# Functions
# mv(file_path): downloads the file to file_path
print(message.number)
print(message.content)
# MultiMediaMessage
print(message.content_type)
message.mv("./image." + message.extension)messages = client.get_messages() -> MessageContainer list
# Same as abovesent_messages = client.get_sent_messages() -> MessageContainer list
#Same as abovefiltered = client.get_messages().get(number="number")# This will wait for a response from someone and return the Message
msg = client.wait_for_response("number")
# This function will work with a message object too
unreads = client.get_unread_messages()
for unread in unreads:
msg = unread.wait_for_response()import pytextnow as pytn
client = pytn.Client("username", sid_cookie="connect.sid", csrf_token="_csrf")
@client.on("message")
def handler(msg):
print(msg)
if msg.type == pytn.MESSAGE_TYPE:
if msg.content == "ping":
msg.send_sms("pong")
else:
msg.mv("test" + msg.extension)During an auth reset if a cookie is not passed and there is no stored cookie in the file it will raise this error.
- Fixed MultiMediaMessage causing error
- Removed user_cookies.json
- Bug fixes
- Added pauses after requests
- Fixed newline bug
- Fixed login bug
- Updated MANIFEST
- Fixed 'Messgage not sending' error
- Added new required cookie
csrf_tokenheader is automatically fetched
- Added get_username.mp4 video
- Changed Client system from email to username. You now input your textnow username instead of email.
- Bug fixes
- Bug Fixes
- New better way of getting new messages with Client.on method
- Client.on works like an event handler that takes a decorator function and calls it with the parameter of one Message object
- Bug Fixes
- Added examples
- Get cookie.mp4 video
- Smarter cookie detection
- bug fixes
- bug fixes
- bug fixes
- Import Bug Fixes
- bug fixes
- if a cookie argument is passed to
Clientit will overide the stored cookie. - cookie argument can now be passed to
client.auth_reset() - Changed import name from
TNAPItopytextnow
#Pre 1.1.0
import TNAPI as tn
# Now
import pytextnow as pytn- Bug fixes
Clienthas new functionclient.wait_for_response(number, timeout=True). Documentation on how to use it aboveMessagehas same function but the number argument is set to the number who sent the message.client.Message.wait_for_response(timeout=True)
- Fixed config json.JSONDecodeError
- new Class
MessageContainerthat acts as a list with some added functions and__str__() MessageContainerhas methodgetwhich will return aMessageContainerthat filtered through all messages- Fixed readme.md Usage section.
-
Complete overhaul of the way this module works.
-
client.get_new_messages()is now deprecated and no longer in use. Instead of that use the new methodclient.get_unread_messages()which will return all unread messages. It will return the same thing each time unless you mark the messages as read withMessage.mark_as_read() -
MessageandMultiMediaMessageclass have a newmark_as_read()method to mark the message as read.mark_as_read()will make a POST to the textnow.com server. -
client.get_messages()now returns a list ofMessageorMultiMediaMessageclasses. For the old function which returned the raw dict useclient.get_raw_messages() -
client.get_sent_messages()is a new method that gets all messages you have sent -
client.get_received_messages()is a new method that gets all messages you have received regardless of whether or not it has been read. -
client.get_read_messages()is a new method that returns all messages that have been read by you.
- Bug Fixes
- Bug Fixes
- Bug Fixes
- Linux
__file__not absolute. Used os.path.abspath
- Bug fixes
- Added constants such as
- SENT_MESSAGE_TYPE
- RECEIVED_MESSAGE_TYPE
- MESSAGE_TYPE
- MULTIMEDIAMESSAGE_TYPE
- Fixed MultiMediaMessage.mv() function
- No longer have to use selenium to authenticate. Now you have to manually grab connect.sid cookie.
- Nothing much
- Using Message and MultiMediaMessage classes instead of dictionary for /get_new_messages/get_sent_messages
- get_messages still returns old dictionary
- Fixed user_sids.json overwrite problem
- Fixed the receiving messages. Now working 100%
- Added FailedRequest and InvalidFileType errors to Client instance
- bug fixes
- Added
Client = TNAPI.Clientin __init__.py - Fixed the failed login import in TNAPI.py
- Receiving messages are better but not good
- Nothing much
- Initial Commit
- Can send messages and photos/videos
- receiving messages a work in progress
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.