In the discrete case, when both state spaces $\mathfrak X$ and $\mathfrak Y$ are finite or countable, the notion of almost sure simplifies into sure and any function $f:\mathfrak Y\longmapsto f(\mathfrak Y)\subset\mathbb R$ is measurable wrt the counting measures.
Now, in the discrete case,
\begin{align}
\mathbb E[Xf(Y)]&=\sum_{x\in\mathfrak X,\,y\in\mathfrak Y}xf(y)\mathbb P(X=x,Y=y)\\
&=\sum_{x\in\mathfrak X,\,y\in\mathfrak Y}xf(y)\mathbb P(X=x|Y=y)\mathbb P(Y=y)\\
&=\sum_{y\in\mathfrak Y}\underbrace{\left\{\sum_{x\in\mathfrak X}x\mathbb P(X=x|Y=y)\right\}}_{\stackrel{\text{(a)}}{=}\,\mathbb E[X|Y=y]}f(y)\mathbb P(Y=y)\\
&=\sum_{y\in\mathfrak Y} \mathbb E[X|Y=y] f(y)\mathbb P(Y=y)\\
&= \mathbb E\{\mathbb E[X|Y] f(Y)\}
\end{align}
where equality (a) is using the standard definition of the conditional expectation in the discrete case. This is essentially the proof of the Law of Total Expectation with an extra $f(Y)$. And this means that $\mathbb E[Xf(Y)]$ can be written as a particular $\mathbb E[\varphi^0(Y)f(Y)]$, when$$\varphi^0(y)=\mathbb E[X|Y=y]$$
Conversely, if there exists a function $\varphi:\mathfrak Y\longmapsto \text{conv}(\mathfrak X)$ [where $\text{conv}(\mathfrak X)$ denotes the convex envelope of $\mathfrak X$ in order to include all possible combinations of the elements of $\mathfrak X$] such that
$$\mathbb E[Xf(Y)] = \mathbb E[\varphi(Y)f(Y)]\tag{1}$$
for every real function $f:\mathfrak Y\longmapsto\mathbb R$, (1) applies to the indicator function $$f_\xi(y)=\mathbb I_{y=\xi}=
\begin{cases}1 &\text{ if }y=\xi\\0 &\text{ if }y\ne\xi\\
\end{cases}$$ for every $\xi\in\mathfrak Y$. This leads to
$$\mathbb E[X\mathbb I_{Y=\xi}]=\underbrace{\mathbb E[\mathbb E[X|Y=\xi]\mathbb I_{Y=\xi}]}_{\stackrel{\text{(b)}}{=}\,
\mathbb E[X|Y=\xi]\mathbb P(Y=\xi)}$$
being equal by (1) to
$$\underbrace{\mathbb E[\varphi(\xi)\mathbb I_{Y=\xi}]}_{\stackrel{\text{(c)}}{=}\,\varphi(\xi)\mathbb P(Y=\xi)}$$
where both (b) and (c) are explained by the fact that
$$\mathbb E[\mathbb E[X|Y]\mathbb I_{Y=\xi}]=\mathbb E[\underbrace{\mathbb E[X|Y=\xi]}_{\text{constant}}\mathbb I_{Y=\xi}]=\mathbb E[X|Y=\xi]\times\mathbb E[\mathbb I_{Y=\xi}]$$
and
$$\mathbb E[\varphi(Y)\mathbb I_{Y=\xi}]=\mathbb E[\varphi(\xi)\mathbb I_{Y=\xi}]=\varphi(\xi)\times\mathbb E[\mathbb I_{Y=\xi}]$$
Hence to$$\varphi(\xi)=\mathbb E[X|Y=\xi]$$for all $\xi$'s such that $\mathbb P(Y=\xi)>0$.