Get custom notifications when you, your company, or anything you care about is mentioned on Twitter/X, even if they don't tag you directly.
This template will help you:
This val tracks mentions of "Val Town" and related terms, excluding noise like retweets and irrelevant accounts. Notifications are sent to a Discord webhook but can be easily reconfigured for other platforms.
To see exactly how we use this template at Val Town: https://www.val.town/v/stevekrouse/twitterAlert
To use this template, fork this val on the top right corner of this page.
The CODE
box shows you the the full source code of this val, you may need to scroll down to see it.
Define what you want to search for by modifying query
:
const query = "\"val.town\" OR \"val.run\" OR \"val town\" -_ValTown_ -is:retweet -from:valenzuelacity -from:val__run";
Refer to Twitter's search operators to fine-tune your query.
Set isProd = false
in the code if you are testing, to ensure there are enough tweets to display.
Toggle it back to true
when you're ready to run this cron job in production and actuall send notifications.
This template uses a Discord webhook for notifications, but
you can update this to your preferred platform by replacing the discordWebhook
call
with a call to Slack, @std/email
, etc.
Create a Discord webhook following this guide.
Save your Discord Webhook URL in your Val Town environment variables:
mentionsDiscord
This val uses the SocialData API for Twitter data:
socialDataSearch
function.