My task is to transfer the file received from a third-party resource to the bot, and then to the user's chat without confirmation from the user, saving the file in the user's channel. I am using bot builder 4 to create a bot for Teams. I need to send attachments to the user's chat. But when I try to do this, I get a 404 error in response.
the function I use
export async function getUploadedAttachment(turnContext) {
const imageData = fs.readFileSync(path.join(__dirname, '../resources/image.png'));
const connectorFactory = turnContext.turnState.get(turnContext.adapter.ConnectorFactoryKey);
const connector = await connectorFactory.create(turnContext.activity.serviceUrl);
const conversationId = turnContext.activity.conversation.id;
const responce = connector.conversations.uploadAttachment(conversationId, {
name: 'image.png',
originalBase64: imageData,
type: 'image/png'
});
// Retrieve baseUri from ConnectorClient for... something.
const baseUri = connector.baseUri;
const attachmentUri = baseUri + (baseUri.endsWith('/') ? '' : '/') + `v3/attachments/${encodeURI(response.id)}/views/original`;
return {
name: 'image.png',
contentType: 'image/png',
contentUrl: attachmentUri
};
}
What do I get in response
code: undefined,
statusCode: 404,
request: WebResource {
streamResponseBody: false,
url: 'https://smba.trafficmanager.net/amer/v3/conversations/a%3A1dTMkfArgCiw6Rul0Ufyk1W4zUWY1l5VpU3wylTjckFCv03ywIqsN1pzD--fDRWupM92sb5rN6x0tl8U_gF6Z4ZwWC8n0KbcEWM5pd9GEKL7JogAp0IWnjzKWQRbxxaAQ/attachments',
method: 'POST',
headers: HttpHeaders { _headersMap: [Object] },
body: '{}',
query: undefined,
formData: undefined,
withCredentials: false,
abortSignal: undefined,
timeout: 0,
onUploadProgress: undefined,
onDownloadProgress: undefined,
proxySettings: undefined,
keepAlive: undefined,
agentSettings: undefined,
operationSpec: {
httpMethod: 'POST',
path: 'v3/conversations/{conversationId}/attachments',
urlParameters: [Array],
requestBody: [Object],
responses: [Object],
serializer: [Serializer]
}
},
response: {
body: '',
headers: HttpHeaders { _headersMap: [Object] },
status: 404
},
body: undefined
}
I also used an example from https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/javascript_nodejs/15.handling-attachments
Thanks!
Teams uses different mechanisms for interacting with bot framework bots in many cases. Sample 15 is for other channels. In the samples repo, if you scroll down to 50 or so you will find Teams-specific samples. Sample 56 concerns file uploads in Teams, and you should start from there instead.