Package: tootnotify
TootNotifyThis is a python command line utility based onMastodon.py, which is able to send direct messages to a given user on Mastodon:foo@bar:~$> tootnotify -r @user@instance -m "Message from TootNotify!"I built this tool tonotify myself via a secondary (bot) Mastodon account, when long-running processes and tasks finish. FIY,you don't need a second account to use TootNotify, you can use your own account and DM yourself! Also, I'm sure there can be many more uses for this tool.Becasue of the way Mastodon works, direct messages are just regularTootsthat mention a single user on the content of its body, and are set to haveprivatevisibility (only the accounts mentioned can see theToot).This tool allows toattachimage, video and audio files to the direct message:foo@bar:~$> tootnotify -r @user@instance -m "Message with media" -f image1.png image2.jpgDue to mastodon's API specifications, media attached to posts must be of the same type: only images (up to 4 images perToot), only video (asinglevideo fileor GIF), or only audio (a singleaudiofile).The current implementation allows the API to determine the MIME type of each media file by the media's extension.Note that theseattachments are done asynchronouslyfollowing Mastodon's guidelines, and theTootis not sent until all data is uploaded (confirmed by the API call), which means your notification may take a few seconds to be sent while the attachments are uploaded.If the upload takes more than the stipulated timeout parameter, theTootis sent without any media(better to receive an incomplete notification than no notificatio at all!).There are also command line arguments to flag your post assensitive content(which will blur out the media you upload), as well as labeling the direct message with aspoiler/content warning, which will force the recipient to read your warning and clickShow Moreto see the body and attachments of the message.Mastodon APITo use this tool you will need to have a Mastodon API application created, with its corresponding API credentials.The simplest way to do this, is through the Mastodon web interface: go to Preferences > Development (i.e.mastodon.social/settings/applications)Once there, click on theNew Applicationbutton. There, give your application a Name, and click theSubmitbutton on the bottom of the page. Having created an App on your account, you should be presented with aClient key, aClient secret, andYour Access Token. You'll need to put these strings into a text configuration file called.tootnotifyrclocated in your$HOMEdirectory, as instructed below.InstallationThis section presents the steps needed to install TootNotify, once the API credentials have been obtained.Create~/.tootnotifyrcfileTootNotify looks for API credentials stored as variables in the~/.tootnotifyrcfile within the users$HOMEfolder. By default,the.tootnotifyrcfile is not shipped with the project, which means you need to create it:foo@bar:~$> touch ~/.tootnotifyrcMake sure that the content of~/.tootnotifycorrespond to the following (and be sure to assign values to these variableswithout any quotes!):## FILE: ~/.tootnotifyrc[tootnotify]# Instance url (e.g. https://mastodon.social)api_base_url=YOUR_INSTANCE_URL# API Client Keyclient_id=YOURCLIENT_ID# API Client Secretclient_secret=YOUR_CLIENT_SECRET# API Access Tokenaccess_token=YOU_ACCESS_TOKEN# Default recipient for the private toots (e.g. @account@mastodon.social)DEFAULT_RECIPIENT=YOUR_DEFAULT_RECIPIENTAmong the variables, a DEFAULT_RECIPIENT can be configured, so that when using TootNotify systematically to notify the same user, the recipient address doesn't have to be provided every time:foo@bar:~$> tootnotify -m "Message to the default recipient!"Install via PIPOnce the~/.tootnotifyrccontrol file is in place, we can use PIP to install TootNotify (make sure you navigate to the root of theTootNotifyproject folder):foo@bar:TootNotify$>pipinstall.We can check whether TootNotify was installed correctly, by invoking it (from anywhere) and passing it the-h/--helpflag:foo@bar:~$>tootnotify-hand if all goes well, we should be presented with the help dialog:usage:tootnotify[-h][-r<@user@instan.ce>][-m<message_body>][-s<spoiler_description>][-f<path_to_media_file>[<path_to_media_file>...]][-x][-t<timeout_in_seconds>][-v][--version]SendaDirectMessagetosomeoneonMastodon!

optionalarguments:-h,--helpshowthishelpmessageandexit-r<@user@instan.ce>,--recipient<@user@instan.ce>Userwhowillreceiveadirectmessage.-m<message_body>,--message<message_body>Bodyofthemessagetobesent.-s<spoiler_description>,--spoiler<spoiler_description>Descriptionforthespoilerwarningwhichhidesthemessage.-f<path_to_media_file>[<path_to_media_file>...],--files<path_to_media_file>[<path_to_media_file>...]Listofupto4mediafilestoattachtothemessage.-x,--sensitiveFlagpost/mediaassensitivecontent(blurmedia).-t<timeout_in_seconds>,--timeout<timeout_in_seconds>Numberofsecondstowaitforasinglemediafiletoupload.-v,--verbosePrintoutverbosemessages.--versionshowprogram'sversionnumberandexitUsage from the command lineThis section presents several examples on how to use TootNotify from the command line once it has been installed.Toot to a single userfoo@bar:~$> tootnotify -r @user@instance -m "Message!"Toot with spoiler/content warningfoo@bar:~$> tootnotify -r @user@instance -s "Movie spoiler" -m "I can't believe Jhon dies at the end of the movie!"Toot and single media filefoo@bar:~$> tootnotify -r @user@instance -m "Look at this animation!" -f animated.gifToot and multiple media filesfoo@bar:~$> tootnotify -r @user@instance -m "Nice image gallery!" -f image1.png image2.jpg image3.jpegIf more than four media files are passed totootnotify -fonly the first four media files will be attached to the direct message.Toot with 'sensitive' mediafoo@bar:~$> tootnotify -r @user@instance -m "Check out this sensitive content!" -f sensitive.png -xCombining optionsAll these arguments can be used in combination with one another, meaning aTootcan: have a message body, have up to four images attached, have a spoiler/content warning, and be flagged as 'sensitive'!foo@bar:~$> tootnotify -r @usert@instance -m "Check out this sensitive gallery!" -f 1.png 2.png 3.png 4.png -s "Very blue images containing numbers and circles" -xToot to multiple usersThis is an unintended use case, and it's sort ofhacky, but you can add multiple recipients to theToot, by adding multiple Mastodon handles with their respective instances as aquoted stringpassed to the-r/--recipientargument:foo@bar:~$> tootnotify -r "@user1@instance1 @user2@instance2" -m "Group Message!"License NoticeTootNotify Copyright (C) 2023 Jorge A. Duarte
This program comes with ABSOLUTELY NO WARRANTY; for details seeLICENSE. This is free software, and you are welcome to redistribute it under certain conditions; seeLICENSEfor details.