Post an activity with attachment occurs 502
ajishanv opened this issue · 3 comments
ajishanv commented
Error:
directLine
.postMessageWithAttachments({
type: "message",
text: "Send base64 Uri file.",
from: {
id: state.currentUser.user.userID,
name: state.currentUser.user.displayName,
role: "agent",
},
attachments: [
{
contentType: "image/png",
contentUrl: attachment.uploadedFiles[0],
name: "test",
},
],
})
It works well if I comment the attachments then sent text only using post @activity to BotFramework.
What's the problem?
ramfattah commented
Hi @ajishanv,
I'm not able to reproduce this issue. I was able to send a message from the client to the bot with the ability to include attachments.
I tested the .postMessageWithAttachments
method in WebChat Client.
Exaple:
- Creates a new instance of the DirectLine object from the botframework-directlinejs library
const directLine = window.WebChat.createDirectLine({
token: token
});
Sharing the WebChat's createDirectLine method implementation detail.
- Call .postMessageWithAttachments method
directLine.postMessageWithAttachments({......})
Sharing full WebChat/DirectLine client code:
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<style type="text/css">
html,
body {
background-color: #f7f7f7;
height: 100%;
}
body {
background-image: url(/images/BotServices-Translucent.svg);
background-position: 100% 100%;
background-repeat: no-repeat;
background-size: auto 50%;
margin: 0;
}
#webchat {
border-radius: 4px;
box-shadow: 0 0 8px rgba(0, 0, 0, 0.08);
height: calc(100% - 20px);
left: 10px;
overflow: hidden;
position: fixed;
top: 10px;
width: 360px;
}
</style>
</head>
<body>
<div id="webchat"></div>
<script>
async function fetchToken() {
const res = await fetch('http://localhost:5001/api/directline/token', { method: 'GET' });
const { token } = await res.json();
console.log("Token is: ", token);
return token;
}
async function initializeWebChat() {
const token = await fetchToken();
const directLine = window.WebChat.createDirectLine({
token: token
});
const files = {
attachments : [
"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxISEhUSExMVFhUWGBUcFRUXGBoWFhYfFx8XFxgYGBgYHykhGBwmHBgbIjIjJiosLy8vFyE0OTQuOCkuLywBCgoKDg0OHBAQHC4nHycuLi4uMC4uMy8uNi42Li4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XPLcAVtlOdTR6kWSMXsmBWjslXik2jMOTXKx/OGNQf6qht4drCGJ5OZA8KjUsx0VQOpJIFPW4Gw2srGGF9ZSC8x01kkJd+XPBPDnyUV6XgNBxUqj9ijjJ3shkooor0ZRMEVyNbuf1zAeipn5kqR+QrsooDmtbVYwQgxk5JySWOgyzHVjgAZJ5AeVFdNFAFYrNFAVVvPuRLaM1xYIXhJLSWa+8hOrNbenXuv3egEXsja6SDKNnBww5MpHNWU6qR5GropY3j3KtLtu8YNFPjSeE8EnTRtOGQaDRgfTFc7F8PhX12ZvpV3DTkQVpfA11+0ioK53M2rAf0T290g5Ek28p+IwyfMEfCuU2G2ANNmsT/wD024H48f8AtXAqcFrJ6K/zRcjioWJq/vFVSSQAASSeQA5k1LdmELeyNOwI9qleVQdDwYSKI/OONW+9S9svcW7umDbQZI4ND7LExZpMa8MsmgC+i8/MVZ0cYUAAAAAAAaAAcgB0FdrhmAeGTct2VcRWz6LY2UUUV1isYpS333R9s4Z4GEV3ECIpT7rrzMMwHvRk/NScjqC3VisZRUlZhOxS1vvA0Mns95G1tOPoSe4/TMUnuuD8anUvqfdq7KguYzFPEkqH6LqGA9RnkfUa0mz9lkC62l1c2w6R8QmiX4JKCf4q4uI4LCbvTduzLcMU16jQLyg3tfH/AOPtoLy2hC/q1sVP8Mtfadn98fevoF/ZtmP9U1Uf6JV7G74qJpkvqi7/AGyiEJktI3uRIC8r+iRrlmprtOzmPnPc3M3mgZYE/wCiA/8AHTLsnYdtagi3hjjz7xVQGb1ZveY+pJq1Q4Gk71JfQ1yxfRCRulufNLMl7fIE7s8VvbZDcDdJpiNDJ1VRnh+NWTRRXdhCMIqMVZIpyk5O7M0UUVmQFFFFAFFFFAf/2Q=="
]
}
window.WebChat.renderWebChat({
directLine: directLine,
userID: 'YOUR_USER_ID',
username: 'Web Chat User',
locale: 'en-US'
}, document.getElementById('webchat'));
directLine.postMessageWithAttachments({
type: "message",
text: "Testing",
from: {
id: "YOUR_USER_ID",
name: "Web Chat User",
role: "agent"
},
attachments: [
{
contentType: "image/png",
contentUrl: files.attachments[0], // base64 encoded image
name: "test"
}
]
})
.subscribe(
id => console.log(`Posted activity with attachment, assigned ID ${id}`),
error => console.log(`Error posting activity with attachment ${error}`)
);
}
initializeWebChat();
</script>
</body>
</html>
and the C# on message activity handler code for the bot:
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Schema;
namespace Microsoft.BotBuilderSamples.Bots
{
public class EchoBot : ActivityHandler
{
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
var replyActivity = MessageFactory.Text($"You sent '{turnContext.Activity.Text}'");
if (turnContext.Activity.Attachments != null && turnContext.Activity.Attachments.Any())
{
// Add a text to the reply indicating that an attachment was received
replyActivity.Text += "\nAnd you've sent an attachment.";
// Iterate over the attachments
foreach (var attachment in turnContext.Activity.Attachments)
{
// Echo back the attachment
replyActivity.Attachments.Add(attachment);
}
}
await turnContext.SendActivityAsync(replyActivity, cancellationToken);
}
}
}