4

I am trying to find a way to run a piece of code (MS Bot Framework, C# hosted on Azure) every time a person is mentioned on Yammer or receives a direct message.

The two ways that I tried:

1) The best I came up with for now is to enable email notifications from Yammer, and watch a mailbox for emails from notifications@yammer.com. Microsoft's Bot Framework has a one-click setup for monitoring emails, so that works.

But notification emails arrive with a 15 minutes delay, which renders this pretty useless as I need near-instant performance.

Finally, it looks like this approach simply doesn't work because the MS Bot Framework seems to reply to the email address who sent the email, rather to the one that I specify:

    if (activity.ChannelId == "email" && activity.From.Id == "notifications@yammer.com")
    {
        var newActivity = activity.CreateReply();

        //doesn't work, sends email back to the activity.From.Id
        newActivity.Recipient.Id = "k48@gmail.com";
        newActivity.Text = "I got a message from " + activity.From.Name + "!";
        BotUtils.SendActivityToChat(newActivity);
    }

I could write my own code for sending emails to an arbitrary recipient, but then there is still the problem with 15 min delay.

2) Another approach I am using is to poll Yammer's API every minute to see if there are new messages, but this is still not instant, and I'm not sure if my account gets banned if I keep polling the API way too often. (Update: the official rate limit is 1 poll per minute, or else they ban you).

Is there something I missed? How else would you run a piece of code every time you get a message or mention on Yammer?

  • 1
    About the reply, maybe the framework doesn't allow you to reply to a different address than the sender. Can you try creating a brand new email instead of `CreateReply()`? – sashoalm Oct 07 '16 at 07:48
  • 1
    About the polling, from https://developer.yammer.com/docs/rest-api-rate-limits - API calls are subject to rate limiting. Exceeding any rate limits will result in all endpoints returning a status code of 429 (Too Many Requests). Rate limits are per user per app. There are four rate limits: Autocomplete: 10 requests in 10 seconds. Messages: 10 requests in 30 seconds. Notifications: 10 requests in 30 seconds. All Other Resources: 10 requests in 10 seconds. – sashoalm Oct 07 '16 at 07:49
  • @sashoalm Unfortunately that same page for rate limits says "When polling for messages, do not exceed one poll per minute. Apps that poll excessively will be blocked". I'll try sending a new email though. Thanks! –  Oct 07 '16 at 08:04
  • One minute is still better than 15 minutes, so you might use that until you think of something better. – sashoalm Oct 07 '16 at 08:09

1 Answers1

1

The BotFramework will not allow you to reply to a message to a different address than the sender. However, if the recipient is one that the bot has received a message from before, you can send them a Proactive Message. To send a proactive message, you can keep the ServiceUrl and the user’s ChannelAccount (extracted from one of the messages from that user) and use this data to send a new activity from your bot to that user.

Here is an example in C#

Here is an example in Node.js

Lars
  • 9,976
  • 4
  • 34
  • 40