It's either parasite or bacterial. It's definitely an infection. Generally speaking, with parasite infections you'll see an increase in movement, darting, zig zag dance, etc. You'll also eventually see some weight loss. With bacterial I've seen more of a lethargic nature, not as much weight loss in most cases and more likelihood of food refusal. Also you're a lot more likey to see internal bacterial infections if you have cases of chronic constipation and keeping bettas at cold temps and poor water conditions while parasite infections tend to happen from feeding live or sometimes even frozen foods, but not freeze dried.
You're a lot more likely to have a bacterial infection, imho, but there's not guarantee.
Epsom salts for sure. Then you can either use the kanaplex bath for bacterial treatment, or treat for parasites with an antiparasite feed or I know AyalaCookiejar had some luck with some Jungle Parasite Clear product.
If you're using Kanaplex you need to treat for two full weeks using the instructions on the tube and then reevaluate. If you're going for parasites then you treat a minimum of two weeks AND at least one full week past when symptoms completely disappear. Meaning, if he's pooping totally normal after one week continue for two weeks. If he's not pooping totally normal until the end of two weeks treat a total of three. You can also mix up feed for internal parasite infections, or use a bath like the Parasite Clear stuff.