microsoft / botframework-sdk

Bot Framework provides the most comprehensive experience for building conversation applications.
MIT License
7.5k stars 2.44k forks source link

[Skype] Regular expression not working to find email address in chat message? #4024

Closed gcfabri closed 6 years ago

gcfabri commented 6 years ago

Bot Info

Issue Description

I built a bot using Bot Framework (node.js) with four connected channels (Messenger, Telegram, Skype and Web). At any moment the bot validates an inputted email address using a regular expression like this below:

/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i

It is working properly on all channels, except the Skype. E.g: gcfabri@gmail.com match with this regex but on Skype channel it doesn't happens.

Code Example

emailRegex.test(gcfabri@gmail.com);

Expected Behavior

The email address gcfabri@gmail.com should match with the regex above.

Actual Results

Skype channel just ignore the step with the regex validation.

nwhitmont commented 6 years ago

Hi @gcfabri - You need to verify that the content being returned by Skype channel is actually a plain-text email address. Sometimes Skype wraps email addresses in HTML tags, so you would need to adjust your RegEx accordingly.

On Skype channel you need to check for: <a href="mailto:name@email.com">name@email.com</a>

devedse commented 6 years ago

@nwhitmont , I personally think this is a bad solution as the field that's being filled now also contains the ... which is infact not a valid URL. This would mean we would have to manually implement code to parse this again.

I'm not sure what a good solution would be (e.g. either enforce skype to send non URL messages if it's talking to a bot, or create an attribute that parses our the URL). But I think this issue should be reopened.

vcardins commented 6 years ago

I'm facing the same problem with Slack, I tried using the following PromptValidator but still didn't get it to work . (SDK v4)

public static PromptValidatorEx.PromptValidator<TextResult> GetEmailValidator(string scapeKeyword = "", string message = null) {
    return async (ITurnContext context, TextResult result) => {
        string email = Regex.Replace(result.Value.Trim(), @"(<a[^>]+>)(.*?)(<\/a>)", (m) => m.Groups[2].Value);
        try
        {
            var value = new System.Net.Mail.MailAddress(email);
            result.Value = value.Address;
        }
        catch
        {
            result.Status = PromptStatus.NotRecognized;
            await context.SendActivity(message ?? $"{email} is an invalid email");
        }
    };
}
usheveta commented 6 years ago

Hi,

I tried doing the following - var newGroupMailboxEmailAddress = Regex.Replace(MailboxrequestFormData.GroupMailboxEmailAddress, "</?(a|A).*?>", ""); This will remove the hyperlinks while saving the data and the data gets saved without any error.

Above values are coming from FormFlow.

Harshgupta71 commented 5 years ago

Hi All,

I was facing the same issue and I found the below regular express which resolved my issue.

@"\b(?!mailto\:)([\w-]+(.[\w-]+)@([a-z0-9-]+(.[a-z0-9-]+)?.[a-z]{2,6}|(\d{1,3}.){3}\d{1,3})(:\d{4})?)"

Thanks