示例#1
0
 public ActivityService(RallyNowDbContext dbContext)
 {
     _dbContext = dbContext;
     _moxtraService = new MoxtraService(dbContext);
     _userService = new UserService(dbContext);
     _mapper = new MoxtraConversationsDtoToActivityModelsMapper();
 }
 public ActivitiesController(RallyNowDbContext dbContext)
 {
     _dbContext = dbContext;
     _service =new ActivityService(_dbContext);
 }
示例#3
0
 public OutlookController(IConfiguration configuration, RallyNowDbContext dbContext)
 {
     _dbContext = dbContext;
     _configuration = configuration;
 }
示例#4
0
 public IntelligenceService(RallyNowDbContext dbContext)
 {
     _dbContext = dbContext;
 }
示例#5
0
        public async Task<ActionResult> Inbox(RallyNowDbContext dbContext)
        {
            string token = Context.Session.GetString("access_token");
            string email = Context.Session.GetString("user_email");
            if (string.IsNullOrEmpty(token))
            {
                // If there's no token in the session, redirect to Home
                return Redirect("/");
            }

            try
            {
                OutlookServicesClient client = new OutlookServicesClient(new Uri("https://outlook.office.com/api/v1.0"),
                    async () => { return token; });

                client.Context.SendingRequest2 += (sender, e) => InsertXAnchorMailboxHeader(sender, e, email);

                var mailResults = await client.Me.Messages
                                  .OrderByDescending(m => m.DateTimeReceived)
                                  .Take(20)
                                  .Select(m => new Emails {
                                      Id = m.Id,
                                      Subject = m.Subject,
                                      DateTimeSent = m.DateTimeReceived.Value.LocalDateTime,
                                      From = m.From.EmailAddress.Name,
                                      Body = m.BodyPreview,
                                  })
                                  .ExecuteAsync();

                foreach (var mailResult in mailResults.CurrentPage)
                {
                    var existingEmail = _dbContext.Emails
                        .SingleOrDefault(c => c.Id == mailResult.Id);

                    if (existingEmail == null)
                    {
                        var activity = new Activity
                        {
                            Date = mailResult.DateTimeSent,
                            MessageSource = "Email",
                            Message = $"Subject: {mailResult.Subject} \r\n Body: {mailResult.Body}",
                        };

                        WebClient webClient = new WebClient();
                        var response = webClient.DownloadString(
                            "https://api.projectoxford.ai/luis/v1/application?id=f375bec7-02a2-4119-ab65-ca89ea673b22&subscription-key=11ea75021c944b31bf1a7d7c465175c5&q=" +
                            HttpUtility.UrlEncode(mailResult.Body));
                        JObject jResults = JObject.Parse(response);

                        try
                        {
                            var intent = jResults["intents"][0]["intent"].Value<string>();

                            if (intent != "builtin.intent.none")
                            {
                                var entities = jResults["entities"];
                                foreach (var entity in entities)
                                {
                                    var type = entity["type"].Value<string>();
                                    var resolution = entity["resolution"].Value<string>();
                                }
                            }
                            activity.Action = intent;
                        }
                        catch { }

                        _dbContext.Emails.Add(mailResult);
                        _dbContext.Activities.Add(activity);
                    }
                }

                _dbContext.SaveChanges();
                return Ok();
            }
            catch (AdalException ex)
            {
                return Content(string.Format("ERROR retrieving messages: {0}", ex.Message));
            }
        }