This is about retrieving files attached during Copilot conversations and using them in subsequent nodes or tools like Power Automate.
Attachments Can Be Retrieved from ChannelData
Don’t be fooled by the “Attachments” property in the System Activity – according to the reference site below, attachment information is actually stored in the “ChannelData” property.
So, when I displayed the contents of ChannelData, I found that the file data (in base64 format) is stored in a property called “OriginalAttachments.”
In this example, I’ll use this Base64 data to add file saving functionality to the agent.
Implementation: Saving Attached Files to SharePoint
For this example, we’ll only target the first file that was attached.
*Note: If you want to handle multiple files, don’t use the First function – instead, treat them as a Table or process them in a loop using Foreach.
Building the Power Automate Flow
First, let’s build a Power Automate flow to save the file.
The flow takes the filename and data string as arguments, then uses the “Create file” action to save it. Remember to convert the data string to binary using the base64toBinary function.
*Note: The File type parameter doesn’t seem to be supported yet for Copilot Studio calls, so create the arguments as “String” type instead.
With that, the Power Automate flow construction is complete.
Building in Copilot Studio
Create a topic and retrieve the “contentUrl” of the first file in ChannelData as a string,
Use a combination of Split and Index to extract the data string portion from the contentUrl.
Then retrieve the filename,
And pass these to the Power Automate flow we created earlier.
This completes the implementation.
// Get the contentUrl
Text(First(System.Activity.ChannelData.OriginalAttachments).contentUrl)
// Get the data part
Index(Split(Topic.contentUrl, ","), 2).Value
// Get the file name
Text(First(System.Activity.ChannelData.OriginalAttachments).name)
Testing the Implementation
When you send a file and trigger the topic, the file information is passed to Power Automate,
And the file is successfully saved.
In a future post, I’ll explore using these attached files to build a multimodal agent by combining them with AI Builder.
コメント