From 9b4dac8d8b47bdb940e44b688c61f2e2ca308e5d Mon Sep 17 00:00:00 2001 From: Pawan Koshti Date: Wed, 11 Sep 2024 17:50:44 +0530 Subject: [PATCH 1/3] Fixed issues for these samples --- .../teamsfileupload/TeamsFileUploadBot.java | 96 +++++++++++------- .../demo-manifest/bot-sso-adaptivecard.zip | Bin 4522 -> 4756 bytes .../Pages/conversation-tab.cshtml | 13 ++- .../nodejs/server/views/conversation-tab.html | 25 +++-- 4 files changed, 86 insertions(+), 48 deletions(-) diff --git a/samples/bot-file-upload/java/src/main/java/com/microsoft/bot/sample/teamsfileupload/TeamsFileUploadBot.java b/samples/bot-file-upload/java/src/main/java/com/microsoft/bot/sample/teamsfileupload/TeamsFileUploadBot.java index dac172e10c..7bb024fdfa 100644 --- a/samples/bot-file-upload/java/src/main/java/com/microsoft/bot/sample/teamsfileupload/TeamsFileUploadBot.java +++ b/samples/bot-file-upload/java/src/main/java/com/microsoft/bot/sample/teamsfileupload/TeamsFileUploadBot.java @@ -28,6 +28,8 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.Collections; @@ -51,6 +53,8 @@ public class TeamsFileUploadBot extends TeamsActivityHandler { private static String microsoftAppId; private static String microsoftAppPassword; + private static final String FILES_DIR = "files"; + private TurnContext context; public TeamsFileUploadBot(Configuration configuration) { microsoftAppId = configuration.getProperty("MicrosoftAppId"); @@ -190,51 +194,71 @@ private boolean messageWithDownload(Activity activity) { return messageWithFileDownloadInfo; } - private CompletableFuture> upload( - FileConsentCardResponse fileConsentCardResponse - ) { + + private CompletableFuture> upload(FileConsentCardResponse fileConsentCardResponse) { AtomicReference> result = new AtomicReference<>(); return CompletableFuture.runAsync(() -> { - Map context = (Map) fileConsentCardResponse - .getContext(); + Map context = (Map) fileConsentCardResponse.getContext(); File filePath = new File("files", context.get("filename")); HttpURLConnection connection = null; - try { - URL url = new URL(fileConsentCardResponse.getUploadInfo().getUploadUrl()); - connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("PUT"); - connection.setDoOutput(true); - connection.setRequestProperty("Content-Length", Long.toString(filePath.length())); - connection.setRequestProperty( - "Content-Range", - String.format("bytes 0-%d/%d", filePath.length() - 1, filePath.length()) - ); - try ( - FileInputStream fileStream = new FileInputStream(filePath); - OutputStream uploadStream = connection.getOutputStream() - ) { - byte[] buffer = new byte[4096]; - int bytes_read; - while ((bytes_read = fileStream.read(buffer)) != -1) { - uploadStream.write(buffer, 0, bytes_read); + + try { + URI uri = new URI(fileConsentCardResponse.getUploadInfo().getUploadUrl()); + URL url = uri.toURL(); + connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("PUT"); + connection.setDoOutput(true); + connection.setRequestProperty("Content-Type", "image/png"); + connection.setRequestProperty("Content-Length", Long.toString(filePath.length())); + connection.setRequestProperty( + "Content-Range", + String.format("bytes 0-%d/%d", filePath.length() - 1, filePath.length()) + ); + + try (FileInputStream fileStream = new FileInputStream(filePath); + OutputStream uploadStream = connection.getOutputStream()) { + + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = fileStream.read(buffer)) != -1) { + uploadStream.write(buffer, 0, bytesRead); + } } - } - result.set(new ResultPair(true, null)); - } catch (Throwable t) { - result.set(new ResultPair(false, t.getLocalizedMessage())); - } finally { - if (connection != null) { - connection.disconnect(); + int responseCode = connection.getResponseCode(); + if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED) { + result.set(new ResultPair<>(true, null)); + + } else { + result.set(new ResultPair<>(false, "Failed with HTTP error code: " + responseCode)); + + Thread.sleep(1000); // Simple backoff before retrying + } + } catch (IOException e) { + result.set(new ResultPair<>(false, "IOException: " + e.getMessage())); + + } catch (URISyntaxException e) { + result.set(new ResultPair<>(false, "URISyntaxException: " + e.getMessage())); + + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); // Restore interrupt status + result.set(new ResultPair<>(false, "InterruptedException: " + e.getMessage())); + + } finally { + if (connection != null) { + connection.disconnect(); + } } - } - }) - .thenApply(aVoid -> result.get()); + + + }).thenApply(aVoid -> result.get()); } + + private CompletableFuture processInlineImage(TurnContext turnContext) { Attachment attachment = turnContext.getActivity().getAttachments().get(0); final HttpURLConnection[] connection = {null}; @@ -243,7 +267,8 @@ private CompletableFuture processInlineImage(TurnContext turnContext) { try { // Save the inline image to Files directory. String filePath = "files/imageFromUser.png"; - URL url = new URL(attachment.getContentUrl()); + URI uri = new URI(attachment.getContentUrl()); + URL url = uri.toURL(); connection[0] = (HttpURLConnection) url.openConnection(); connection[0].setRequestProperty("Authorization", "Bearer " + token); try ( @@ -302,7 +327,8 @@ private CompletableFuture> downloadAttachment(Attachment atta HttpURLConnection connection = null; try { - URL url = new URL(fileDownload.getDownloadUrl()); + URI uri = new URI(fileDownload.getDownloadUrl()); + URL url = uri.toURL(); connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); diff --git a/samples/bot-sso-adaptivecard/csharp/demo-manifest/bot-sso-adaptivecard.zip b/samples/bot-sso-adaptivecard/csharp/demo-manifest/bot-sso-adaptivecard.zip index b99c3ebc0aaef156798bf4d0e64215ab8c7096c9..0497160bbc17b061fa7f9081c83f63d7687004b4 100644 GIT binary patch delta 4313 zcmb7|Wmpv2*2jmO0fv%N5k#6HMHos#>698$%8~AFh7hD<=sti0(nu@a4WcllbV+w3 zSI+yMd(Lw|-MiMa>%;!9XFvP@<+q9$5||LGidfj>0MPGT)uq=3{D0u$004vlI)JT- zou!$nvkRA%v%MWmlMn!0R~e_ z=$)dlYOZwU{MT3qHTP7O?rp9pt&(t)(Q`Qi6aFh~oiReqt{$t;tVu_1hJzSf$q_|* zW6CsmqWdg}$psphjnuN04*{y&#WhUdzDn445ecO*I~8QnJiEXA27(`4R=L&O(yJ9- z6}NckT_UgJ!^7)p-!dtc6c89n}-7(wR%m!Z~e)fQw%L^2;=km8?qdQv+H8*^Fcv zD+%ujw6C@U8dZ&4n>v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8vE0Y8q&JUvP3()voZP|#7Mk!|`4>@1bX)0kaaoAc zq`5`z!X?wxhs^ByT!JX2D|M{(1X)6I<#YF3j~!t6`p!}G1@8=5O}26UYBsm*IvlEH zYatS&L(Ib8eHba^Dd`yL=9s|hg{+Hnhu4RU{XD~4O_VxZ{ESCj$=tzxJbZX2qICVI zC>NeJ@hj|9<7}=-{vBTIO$|&3n*Jaui2(o*5CFIi4*+*-4`&B^Uq5jdUr�!*(68 zBuxv?9(9?!F2ja4T!SkV{86nhZ%JjXaA7XcksgU_P@L5e>T3-^Z-_o#(#wFD4DBcl zDGs4?a_r3hFm$o9<~(;i#lMQh*_*Y4l4|Cj@kB^DxeSFn_c=;8t*$+LIY*h2DG7d_ zqD)nXBC=D80KN>Fup03ab5*$_XM3u)R?8LlDf2dajefX2oPh@FE7_D~+@)cZXyYT3 z!_dFK79?50zd$Tr^qCg*ICOa-qG~QjmL|!_XGFzR!h$uyDX^;|6-+}g)_-uI)rUjS z6y@vVj9=Jpncc^Q9g->h#L^W;J^3_p&@jDqP5@#2eLA|fNn0hv?bzgz-AGq2edUE3 z*I7IEfiW?-8b|nfTJBxe#K>^{?!zC$H$T6WA=sK%6>Q_*qGr5p7)Rv-=kao!tJKu7 zoBW`R8LBsQg&xTYgPLw4D)YSA{v^BYuVs4fBR1Y3+V^HOPIsC7;xUP#T^?&%)g8)H)ACg@6 Lvg^7=^Y`jsdY!e! diff --git a/samples/tab-conversations/csharp/TabConversation/Pages/conversation-tab.cshtml b/samples/tab-conversations/csharp/TabConversation/Pages/conversation-tab.cshtml index 10e3f42d48..dda136fce2 100644 --- a/samples/tab-conversations/csharp/TabConversation/Pages/conversation-tab.cshtml +++ b/samples/tab-conversations/csharp/TabConversation/Pages/conversation-tab.cshtml @@ -6,7 +6,9 @@ - + + @@ -76,22 +79,26 @@ Start Conversation To open a conversation - + Close Conversation To close the conversation view - + Continue Conversation To continue a conversation. - + Deeplink to conversation Redirect to channel conversation. - + From bdb90f00f1183c628ec0cb780cdfa950207f5a9c Mon Sep 17 00:00:00 2001 From: Pawan Koshti Date: Mon, 16 Sep 2024 11:55:05 +0530 Subject: [PATCH 2/3] Changes or expert finder --- samples/msgext-expert-finder-js/assets/sample.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/msgext-expert-finder-js/assets/sample.json b/samples/msgext-expert-finder-js/assets/sample.json index 4c4490dabd..5376b6d9c6 100644 --- a/samples/msgext-expert-finder-js/assets/sample.json +++ b/samples/msgext-expert-finder-js/assets/sample.json @@ -4,7 +4,7 @@ "source": "officeDev", "title": "Expert Finder with SSO in Copilot using multi parameter search", "shortDescription": "Microsoft Teams message extension that can be used as a plugin to Search for candidates and share profiles matching a criteria.", - "url": "https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/msgext-expert-finder", + "url": "https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/msgext-expert-finder-js", "longDescription": [ "This sample implements a Teams message extension that can be used as a plugin for Microsoft Copilot for Microsoft 365. The message extension allows users to query the candidates based on their skills, location and availability." ], From 4660b26d6251da8e9264e50c1ae76a723a958ce3 Mon Sep 17 00:00:00 2001 From: Pawan Koshti Date: Mon, 16 Sep 2024 12:34:23 +0530 Subject: [PATCH 3/3] Tab-product inspection fixed for android and IOS --- .../Views/Home/ScanProduct.cshtml | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/samples/tab-product-inspection/csharp/ProductInspection/Views/Home/ScanProduct.cshtml b/samples/tab-product-inspection/csharp/ProductInspection/Views/Home/ScanProduct.cshtml index 412dfff68e..3745e2bf37 100644 --- a/samples/tab-product-inspection/csharp/ProductInspection/Views/Home/ScanProduct.cshtml +++ b/samples/tab-product-inspection/csharp/ProductInspection/Views/Home/ScanProduct.cshtml @@ -23,7 +23,7 @@ let productName; let image = ""; - // Method to scan barcode + //Method to scan barcode function scanBarCode() { var config = { timeOutIntervalInSec: 30 @@ -67,24 +67,37 @@ }, config); } - // Method to capture product image - function captureImage() { + //Method to capture product image + function selectMedia() { microsoftTeams.app.initialize().then(() => { + + var imageProp = { + sources: [microsoftTeams.media.Source.Camera, microsoftTeams.media.Source.Gallery], + startMode: microsoftTeams.media.CameraStartMode.Photo, + ink: false, + cameraSwitcher: false, + textSticker: false, + enableFilter: true + }; - // Method to ask for image capture permission and then capture image - microsoftTeams.media.captureImage((error, files) => { - // If there's any error, an alert shows the error message/code + var mediaInput = { + mediaType: microsoftTeams.media.MediaType.Image, + maxMediaCount: 1, + imageProps: imageProp + }; + + microsoftTeams.media.selectMedia(mediaInput, function (error, attachments) { if (error) { if (error.message) { alert(" ErrorCode: " + error.errorCode + error.message); } else { alert(" ErrorCode: " + error.errorCode); } - } else if (files) { - image = files[0].content; - $("#productImg").attr("src", "data:image/png;base64," + image); - $("#productStatus").show(); - } + } else if (attachments) { + image = attachments[0]; + $("#productImg").attr("src", "data:image/png;base64," + image.preview); + $("#productStatus").show(); + } }); }); } @@ -93,7 +106,7 @@ var productStatus = status ? "Approved" : "Rejected"; const formData = new FormData(); formData.append('productId', productId); - formData.append('image', "data:image/png;base64," + image); + formData.append('image', "data:image/png;base64," + image.preview); formData.append('status', productStatus); $("#productStatus").hide(); $("#captureImage").hide(); @@ -125,7 +138,7 @@
- +