tompaana / twitter-bot-fw-integration

A class library with a sample demonstrating how to add Twitter as one of the Microsoft Bot Framework channels with the help of Direct Line API.
Other
16 stars 5 forks source link

Not receiving proactive messages #2

Open fercom opened 6 years ago

fercom commented 6 years ago

When trying to send proactive messages twitter doesn't show anything, the code I am using is the following:

var userAccount = new ChannelAccount() {Id = activityRecibida.FromId, Name = activityRecibida.FromName};
                var botAccount = new ChannelAccount()
                {
                    Id = activityRecibida.RecipientId,
                    Name = activityRecibida.RecipientName
                };
                string url = activityRecibida.ServiceUrl;

                MicrosoftAppCredentials.TrustServiceUrl(url, DateTime.Now.AddYears(2));
                var appId = System.Configuration.ConfigurationManager.AppSettings["MicrosoftAppId"];
                var appPassword = System.Configuration.ConfigurationManager.AppSettings["MicrosoftAppPassword"];
                var account = new MicrosoftAppCredentials(appId, appPassword);
                var connector = new ConnectorClient(new Uri(url), account);

                IMessageActivity activity = Activity.CreateMessageActivity();
                activity.From = botAccount;
                activity.Recipient = userAccount;
                activity.Conversation = new ConversationAccount() {Id = activityRecibida.ConversationId};
                activity.Text = $"[{from}]: " + message;
                activity.Locale = activityRecibida.Local;
                var response = await connector.Conversations.SendToConversationAsync((Activity) activity);
                await activityLogger.LogAsync(activity);

It works on facebook, emulator and skype, but here it simply doesn't. Do you have any clue? Thanks

tompaana commented 6 years ago

That isn't currently supported by this project.

At the moment we anticipate the Twitter user to be the first one to send a message. Then we match the ID of the forwarded message (to the bot) with the Twitter user ID in order to be able to respond back.

In order for proactive messages to work we need:

So I believe it can be done, but requires a bit of work, which unfortunately I don't have time for in the near future.

If someone wants to tackle this, there are some clues in https://github.com/tompaana/bot-message-routing project.

tompaana commented 6 years ago

Sorry, I forgot to thank you @fercom - This is genuinely valid issue.

fercom commented 6 years ago

@tompaana Maybe I can do something to help you, but I will need to debug your project, any tips? I have tried to debug the Direct Line connections before but it wasn´t successful. I also think that your project could be the key to finally create a bridge between bot framework and whatsapp (here in México and in Latin América it is a big concern). Thank you for your work!

tompaana commented 6 years ago

If WhatsApp provides an API similar to Twitter, I see no reason why this approach would not work for WhatsApp as well.

What kind of a problem do you have with Direct Line?

At the moment this project is polling for messages (not great - I want to switch to using web sockets), and all incoming messages should be intercepted by putting a break point in the method DirectLineManager.PollMessagesAsync (https://github.com/tompaana/twitter-bot-fw-integration/blob/master/TwitterBotFWIntegration/DirectLineManager.cs#L88).

fercom commented 5 years ago

Hi @tompaana, any update on this issue? Thanks!