Donkeys in general appear in a lots of fairy tales.
In "Die Bremer Stadtmusikanten" (Musicians of city Bremen) it has a main role and can sing. But it is never clear, if it can talk to humans. In the story it mainly talks to his collagues: a cat, a dog and a rooster.
In "Der gestiefelte Kater" (Puss in Boots) the 3 boys of a died miller get: oldest the mill, second the donkey and third the cat. Which then get boots and start the magic.
In "Tischlein deck dich, Esel streck dich, Knüppel aus dem Sack" (Table prepare yourself, Donkey stretch yourself, truncheon out of the bag) one of three brothers gets a magic donkey which is able to poop golden coins.
Ali Baba transports the treasures with a donkey, Josef and Maria are drawn with a donkey too. In the old french version of "Allerleirauh" the fleeing girl is dressed in the skin of a donkey, to live "invisible" in the woods.
Donkeys were the working and riding animals of the poorer people. They were used to pull vehicles or help in farming at the field. They turned even some kind of mills. Donkeys where one of the commonst and most important animals in the time, the fairy tales talking about.
And they are famous to be "stubborn"(see "Der kleine Muck"/The small boy Muck, when the fools be grown donkey's ears) but they simple do not flee from danger but stand still and think first (in opposite to horses).
So if the author searched for an intelligent unusual pet-friend for Shrek with connection to the fairytale times, a donkey is absolute logic :)