This repo contains a twitter based binding extension for Azure WebJobs SDK built on top of Tweetinvi and using the Twitter Stream API. Addittionally a simple sample Azure Function project demos how to use the trigger.
Note: I am still actively working on the features of what is here. Please provide feedback and open issues as you find them. I will happilly accept pull requests.
In order to use this trigger you will need to sign up for a Twitter Developer Account and obtain your Consumer keys and generate Access keys. You then need to update your local.settings.json to contain the following:
"TwitterConsumerKey": "<API key>",
"TwitterConsumerSecret": "<API secret key>",
"TwitterAccessKey": "<Access token>",
"TwitterAccessSecret": "<Access token secret>"
// Runs when a tweet containing the word "azure" is detected
public static async Task Run([TwitterTrigger("azure")]MatchedTweetReceivedEventArgs tweetEvent, ILogger log)
{
log.LogInformation($"\n@{tweetEvent.Tweet.CreatedBy.ScreenName}[{tweetEvent.Tweet.CreatedBy.Name}]\n" +
$"Tweeted: {tweetEvent.Tweet.FullText}\n" +
$"HashTags: [{String.Join(",", tweetEvent.Tweet.Hashtags.Select(x => $"#{x.Text}"))}]");
}
// Runs when a tweet containing the hashtag "#azure" is detected
public static async Task Run([TwitterTrigger("#azure")]MatchedTweetReceivedEventArgs tweetEvent, ILogger log)
{
log.LogInformation($"\n@{tweetEvent.Tweet.CreatedBy.ScreenName}[{tweetEvent.Tweet.CreatedBy.Name}]\n" +
$"Tweeted: {tweetEvent.Tweet.FullText}\n" +
$"HashTags: [{String.Join(",", tweetEvent.Tweet.Hashtags.Select(x => $"#{x.Text}"))}]");
}
// Runs when a tweet by @introtocs is detected
public static async Task Run([TwitterTrigger(user: "introtocs")]MatchedTweetReceivedEventArgs tweetEvent, ILogger log)
{
log.LogInformation($"\n@{tweetEvent.Tweet.CreatedBy.ScreenName}[{tweetEvent.Tweet.CreatedBy.Name}]\n" +
$"Tweeted: {tweetEvent.Tweet.FullText}\n" +
$"HashTags: [{String.Join(",", tweetEvent.Tweet.Hashtags.Select(x => $"#{x.Text}"))}]");
}
// Runs when a tweet by @introtocs is detected containing the hashtag "#azure"
public static async Task Run([TwitterTrigger("#azure", "introtocs")]MatchedTweetReceivedEventArgs tweetEvent, ILogger log)
{
log.LogInformation($"\n@{tweetEvent.Tweet.CreatedBy.ScreenName}[{tweetEvent.Tweet.CreatedBy.Name}]\n" +
$"Tweeted: {tweetEvent.Tweet.FullText}\n" +
$"HashTags: [{String.Join(",", tweetEvent.Tweet.Hashtags.Select(x => $"#{x.Text}"))}]");
}
This project is licensed under the MIT License