const runWithErrorHandling = (taskName, taskFunction) => {
try {
taskFunction()
speakText(`${taskName} completed successfully`)
} catch (error) {
sendAgentEmail(
"admin@example.com",
`PhoneClaw Error: ${taskName}`,
`
An error occurred during automation:
Task: ${taskName}
Error: ${error.message}
Time: ${new Date().toISOString()}
`
)
speakText(`Error in ${taskName}, notification sent`)
}
}
// Example usage
runWithErrorHandling("Social Media Post", () => {
magicClicker("Twitter app")
delay(2000)
magicClicker("Compose button")
// ... rest of workflow
})