Targeted, backend-initiated actions can be triggered from event handlers, using methods of state. Internally, this is achieved using Framework’s mail, ephemeral state that is cleared when it reaches the intended user.
The file_download method takes the data and file_name arguments. The first must contain raw bytes (a bytes object) or a packed file. As mentioned in the Application State section of the guide, a packed file is obtained using the wf.pack_file or wf.pack_bytes methods.
def handle_file_download(state): # Pack the file as a FileWrapper object data = wf.pack_file("assets/story.txt", "text/plain") file_name = "thestory.txt" state.file_download(data, file_name)
Framework adds notifications when a runtime error takes place. You can add your own notifications using the add_notification method, which takes the type, title and message arguments. type must be one of error, warning, info, success.
def notify_of_things_that_happened(state): state.add_notification("error", "An Error", "Something bad happened.") state.add_notification("warning", "A Warning", "Be aware that something happened.") state.add_notification("info", "Some Info", "Something happened.") state.add_notification("success", "A Success", "Something good happened.")