3

I want to display a welcome message whenever someone connects to my bot. I've used the technique from the demo-ContosoFlowers sample on github (https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/demo-ContosoFlowers) which works fine in the Bot Framework Emulator, but not in Skype or Facebook Messenger. Specifically, this code in MessageController.HandleSystemMessage doesn't trigger:

        else if (message.Type == ActivityTypes.ConversationUpdate)
        {
            if (message.MembersAdded.Any(o => o.Id == message.Recipient.Id))
            {
                var reply = message.CreateReply(Resources.RootDialog_Welcome_Message);

                ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));

                await connector.Conversations.ReplyToActivityAsync(reply);
            }
        }

Does anyone know how to do this correctly?

2 Answers2

5

I also tried out the ContosoFlowers demo today. I experienced the same behavior you describe: in the emulator, ConversationUpdate code is triggered but in Skype it is not. However, I did notice that the ContactRelationUpdate activity type does fire in Skype (I haven't tried Facebook Messenger). If your goal is to display a welcome message whenever someone "connects" to your bot, you could try using the ContactRelationUpdate activity type like this:

else if (message.Type == ActivityTypes.ContactRelationUpdate)
{
    if(message.Action == "add")
    {
        var reply = message.CreateReply("WELCOME!!!");
        ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));
        await connector.Conversations.ReplyToActivityAsync(reply);
    }
}
Eric Dahlvang
  • 8,252
  • 4
  • 29
  • 50
  • I tested this and now I get the expected behaviour in Skype. Facebook Messenger I'm still uncertain about. I agree that this is better and we have implemented the change, however I would like to send a welcome message when a new conversation starts and not just when a new Contact is added. I'll continue to investigate. Thanks for the help Eric – Peter Bryntesson Mar 24 '17 at 09:10
  • I want to show a "WELCOME UserName!!!" message. Any idea why `message.From.Name` is not available at this state? Because it is available after I send the first message from the user, but I need it as a greeting message ... – SmartDev Jun 29 '17 at 14:36
  • I tried this solution, but I'm getting 'message.Action' as null. – Vidyesh Aug 02 '18 at 05:35
0

Create a class and have this in you callback url of fb. FacebookProfile is my class that holds the name and other information after the call.

 public static async Task<FacebookProfile> GetFacebookProfile(string accessToken)
            {
                var uri = GetUri("https://graph.facebook.com/v2.6/me",
                    Tuple.Create("fields", "name,email,id,first_name,last_name"),
                    Tuple.Create("access_token", accessToken));

                var res = await FacebookRequest<FacebookProfile>(uri);
                return res;
            }
Dev Raj Gautam
  • 121
  • 1
  • 11