As an autistic person who runs the emotional support section of a volunteer organisation, I've got a template!
1 Listen. Make noises (hmm, oh!, nooooo) that accurately respond to what they're saying. You can type any of the above in messages, too! Do this about once a sentence or once every two messages.
2 Whenever they pause, try to name the opinion that they seem to have as an adjective to the situation, but give it 110%. So they were in a fight and the other person said something they feel a bit hurt about? "How dare they say that!" They stubbed their toe and are frustrated? "Oh that's horrible!"
3 Ask them: "How are you feeling now?" If you think you can guess their emotion, you can add: "Am I right to think you're feeling ... or is that inaccurate?" Listen to their response.
4 Ask them what they would appreciate most from you at that moment: to listen, to give advice or to distract them. From here on, follow what they said.
Respect your own boundaries! Only follow this template if you can handle it right now. Don't help others if it will take too much energy or possibly upset you, too. Consider saying "I really want to help you, but right now I can't. I hope you can understand that." Don't apologise, teach yourself and them it's okay to set a boundary. You might also want to start asking others for consent before taking up emotional labour, because friends might start mimicking that habit. Ask something along the lines of "Hey, would it be okay if I told you about something heavy? Do you have the emotional band with for it right now?" After all, if you can't handle me at my worst, you deserve a break.
By the way, if someone has a panic attack and you do want to help them, my template won't work. Instead, the following might.
Tell them that they seem overwhelmed, acknowledge that they might be having a panic or anxiety attack. If they are hyperventilating, advice them to put their hands in a cup before their mouth and nose (thumbs on the cheeks, middle finger on the nose, pinkies against each other) or to breathe into a paper bag if you have one. This will limit the oxygen they're breathing and thus signal their brain to take deeper breaths. Tell them it's okay to have a panic attack, they're allowed, let it wash over, don't push it away. Feelings are to be felt and that's okay. This might make the panic attack get worse, that's good, it's like a wave, it was going to push them under at some point and afterwards things will get better. They must go through the feelings. A panic or anxiety attack may be a signal of feelings going unaddressed for too long (but isn't always, though, so do not make any assumptions for them).
Encourage them to observe what's going on. If they have the ability to talk, ask them to tell you what the panic attack is doing to their body (think of hyperventilating, shaking...), what emotions they are feeling or if they know what triggered it. This allows them to get in a sort of helicopter view, taking some distance from the situation while also earning a deeper understanding of it. Do not start this if they haven't managed to "let it wash over" yet.
After observing their situation a bit, you can suggest they look around them to ground (remind their brain where they are). Help them find something to see, something to hear, something to feel, something to smell and something to taste. For this reason I often carry around a bottle of water but other objects will do aswell. This helps their brain get a grip on reality again bit can only be done after feeling and observing the signals the body and mind are giving off!
Once they have a bit more of a grip on reality, help them breathe through the panic attack. If they are okay with that you can count for them with 7 in, hold for 8 and breathe out 4. At first they may need you to count fast but you can gradually slow it down a bit.
None of these steps are meant to end the panic or anxiety attack: it will go on for however long it will. But these steps can help them through it. If you've been through all four, ask them if they want to repeat any of them - order no longer matters. Otherwise, offer to listen, distract or give them advice. Ask if they have a therapist that they can talk to about this. Do they have panic attacks more often or was this a first? They may not even know for sure (or they never labelled it as a panic/anxiety attack before). A panic attack is often a signal of underlying problems (note: this does not make their feelings any less valid!) so it might be helpful to talk to a professional. You may be able to help a bit but you are not a professional.