# Activities

> The **Communications Mining Activities** package allows you to consume results from the Communications Mining™ streams. In this tutorial you can see an example of the invoice submissions process.

## Get Stream Results and Get Attachments

The **Communications Mining Activities** package allows you to consume results from the Communications Mining™ streams. In this tutorial you can see an example of the invoice submissions process.

You are guided on how to consume a Communications Mining stream, identify invoice submission requests and download the associated attachments from the communications.

## Key Concepts

* **Results** - A representation of a communication that is returned from the Communications Mining™ stream. The results contain two key properties:
  + `comment` - contains all the information about the communication that was uploaded to the platform, such as: the subject, body, and time stamp of the communication.
  + `prediction` - contains the set of predictions that are returned against that communication. Within this property you can find `extractions` and `fields`.
* **Extraction** - A prediction related to a specific instance of a request associated with a label, such as an `Address Change` request, and the fields linked to that request: Address Line 1, Town/City, Zip code. For every label you can predict multiple extractions on each message. Each extraction has an associated `Occurrence Confidence` and an `Extraction Confidence`.
* **Field** - A data point extracted as a value from a message. A field can have the following types:
  + general field (not associated with any labels).
  + extraction field (linked to a specific label and required to process requests associated with that label).
* **Occurrence Confidence** - A model's confidence level about the presence of a specific extraction instance. For instance, how certain the model is about a second `Change of Address` request in the message.
* **Extraction Confidence** - A model's confidence level that an individual extraction is correctly extracted - i.e. the extraction is correctly identified, and all of the fields are correctly identified and associated with the correct extraction.
* **Thresholding** - Each label prediction returned from a stream contains a `thresholds` property. This property contains the list of thresholds that have been surpassed for the given prediction. Currently, the threshold that you configure on the stream is called a `stream`.

**Prerequisites**
* Access to Communications Mining™.
* An exchange integration configured and populating a source.
* A trained dataset based on this source.
* A stream configured on this trained dataset.

Follow the steps below, to consume `stream Results` and `obtain attachments`.

## Step 1 - Connect to your stream

Within a Studio project, drag in the `Get Stream Results` activity from the Communications Mining™ activities library and select your stream.

  ![docs image](https://dev-assets.cms.uipath.com/assets/images/ixp/ixp-docs-image-405078-506f9328.webp)

## Step 2 - Start looping your stream results

Drag in a `For Each` loop and start iterating the `Results` field of the variable output from the `Get Stream Results` activity.

  ![docs image](https://dev-assets.cms.uipath.com/assets/images/ixp/ixp-docs-image-405082-8578fe06.webp)

## Step 3 - Determine if the result is an Invoice Submission

Within your `For Each` loop, add an `If` statement, and check if the `Invoice Submission` request has been detected with the following expression: `result.Prediction.ContainsLabelExtraction("Invoice Submission")`

  ![docs image](https://dev-assets.cms.uipath.com/assets/images/ixp/ixp-docs-image-405070-82bff582.webp)

:::note
You can also access any field values that you have configured for this label with the `result.Prediction.GetLabelExtractions("Invoice Submission")(0).GetField("Invoice Date")` expression.
:::

## Step 4 - Download the attached invoice

Drag in the Get Attachment activity to the `Then` section of your if statement. You can then retrieve the attachment reference with the following expression: `result.Comment.GetAttachmentsByType("application/pdf")(0).AttachmentReference`.

:::note
This expression assumes that at least one PDF attachment exists. Check in production that this is the case.
:::

## Step 5 - Pass the attachment to Document Understanding

You can now use the downloaded attachment and pass it Document Understanding:

  ![docs image](https://dev-assets.cms.uipath.com/assets/images/ixp/ixp-docs-image-405062-5a171a5b.webp)

## Step 6 - Advance the stream

Once you have processed all of the results in the stream batch, use the `Advance Stream` activity to advance the stream to retrieve more results:

  ![docs image](https://dev-assets.cms.uipath.com/assets/images/ixp/ixp-docs-image-405066-84c493cb.webp)
