Drop this into the Transform>Scale prop of the Text Layer -
// calculate textWidth
const myTextWidth_inPixels = thisLayer.sourceRectAtTime(time).width;
// provide edge padding values, for the left and right edges of the panel
const edgesPadding = 50;
// calculate the width of the panel (this scenario uses a Shape Layer's Xsize') add edgepadding
const myTargetWidth = thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Rectangle Path 1").size[0] - edgesPadding;
// calculate the ratio of the text width to the myTargetWidth.
// This value will be used to squash/squish the text if it's width is larger than the myTargetWidth.
const ratioOfText_toTargetWidth = (myTextWidth_inPixels/myTargetWidth);
// use Javascrip ternary (a slimmer ifElse Conditional to check if the ratio of textWidth to targetWidth
ratioOfText_toTargetWidth>1 ? [100/ratioOfText_toTargetWidth,100] : [100,100]
When all is done, you will have to place the position of the text onto the appropriate position; taking into account of the edgePadding you provided earlier. This process can actually be automated but it will also lengthen my post too much for the purpose.
FWIW, for such tasks, it is a good idea that editorial understands the implications of lengthy texts as overly long texts will result in unlegible text. Hence, it is a good idea to provide editorial with guidelines on the max number of lines to use.
HTH
And here's the same Expression without the comments -
const myTextWidth_inPixels = thisLayer.sourceRectAtTime(time).width;
const edgesPadding = 50;
const myTargetWidth = thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Rectangle Path 1").size[0] - edgesPadding;
const ratioOfText_toTargetWidth = (myTextWidth_inPixels/myTargetWidth);
ratioOfText_toTargetWidth>1 ? [100/ratioOfText_toTargetWidth,100] : [100,100]