private async Task MessageReceivedAsync (IDialogContext context, IAwaitable <IMessageActivity> result) { var messageResult = await result; var cvs = new OCRService(); var finalResult = string.Empty; // 上傳圖片的處理 if (messageResult.Attachments?.Any(a => a.ContentType.Contains("image")) ?? false) { var attachment = messageResult.Attachments.FirstOrDefault(x => x.ContentType.Contains("image")); var imageStream = await messageResult.GetConnector().GetImageStream(attachment); var ocrResult = await cvs.GetOcrResultAsync(imageStream, "zh-Hant"); finalResult = ProcessImageOcrResult(context, ocrResult); } // 圖片網址的處理 else if (Uri.IsWellFormedUriString(messageResult.Text, UriKind.Absolute)) { var ocrResult = await cvs.GetOcrResultAsync(messageResult.Text, "zh-Hant"); finalResult = ProcessImageOcrResult(context, ocrResult); } context.Done(finalResult); }