Hello Michal21
Since December 2023, it is no longer possible to purchase tickets on the train when arriving from Milan. The same rule is applied as on all trains in Switzerland: no ticket purchase on trains.
There is a ticket vending machine in Domodossola (I just checked with my colleague sitting next to me right now, who lives in Domodossola and works in Brig).
You either have to purchase the ticket in Domodossola, or you purchase the ticket from Trenitalia or SBB online (web or app).
Kind regards,
Roland