There are two endings of the "sale" of Yoseph, corresponding to the two stories of the "sale." In the E-story, there is no sale; the Midianim simply take Yoseph. In the J-story, the brothers sell Yoseph, to the Yishmaelim.
We read the end of the E-story as Bereshit 45:3:
And Yoseph said to his brothers: "I am Yoseph. Is my father still alive?" But the brothers could not answer him, because they were in shock before him.
Note that there is no mention of a sale. And the end of the J-story is Bereshit 45:4:
And Yoseph said to his brothers: "Come close to me, if you please," and they came close. "And he said, I am Yoseph your brother, which you sold into Mitzrayim.
Note that here there is mention of a sale. And then Bereshit 45:5, which seems to be a combination of sources:
And now, be not distressed, and do not reproach yourselves for having sold me here, for it was to be a provider that God sent me ahead of you.
Here the italics are from E and the bold is from J. The stories are so much alike that they can be told simultaneously.
And what is the message of this? The Torah of E is faultless here (Sanhedrin 102a), though it is only through the Torah of J that we know it. Two wooden tablets in the hand of HaShem as one (Ezekiel 37:19). Even if the brothers sold Yoseph for money, it was for the good. Even bad is, in the end, for the good. Hashem is in control.