First, you have to understand the meaning of the words, the essence of those words can tell you what you are saying if you can mix them with the grammar rules, and be successful in your enterprise.
Will according to the dictionary "used to express desire, choice, willingness, consent, or in negative constructions refusal.
Now the modal "will" as any modal is going to modify your main verb e.g. without modals; I run — with modals; I should run, I could run, I would run, I may run, I might run, and I will run.
Now that we understand that will is the willingness that a person has to do something, modify your verb and project that willingness into the future as a fact, a reality that will happen in the future. I have the intention of doing something in the future and I project that as a fact, a future statement, now you're not just expressing willingness anymore, you are projecting it as a fact a future reality.
Next, you have to understand that there is no such thing as a certain future, you cannot see into the future, but you can predict the future, in here the grammar rules are very important.
Will like we said before, is the a future statement of doing something but you are basing this statement in the will power, the willingness, the belief, the mere positive thought or idea, the feeling you have, the hunch that something is going to happen, meanwhile "be going to" is using present continuous because it is based on facts, real evidence that you have at hand, and has a higher probability that the action is going to happen.
According to the grammar rules "be going to" is used for a near future, reason; the near future has a higher probability of happening.
"Will" is used for the distant future because has a lower probability of happening given that a lot of thing that you can´t prevent or foresee may happen.
"Will" is also used for improvised answers given the fact that in the moment you have the willingness of doing that action and that´s what you are expressing, you are proyecting that willingnes to do the action as a future fact or future statement into the inmediate future, in theory you don´t have the time to think in the facts, you only have the intention, backed up by your emotion.
That is how this thing supposed to be used, but in reality there´s a very thin line between these two words because expressing the percentage of certainty every time you talk is difficult itself and then there´s no one that can tell you the accepted measurement of percentage according to what you are feeling, that´s why you can exchange one for the other, it´s easier than think every time you want to express something in the future "Am I 90% sure that this is going to happen?" If you have to decide because they ask you to do it or you have the need of using this information, do it, if not, don´t do it, your choice, either way any word is accepted, this is just general useless knowledge, but in this case knowledge that can help you with your problem, and if you have the question about if it's possible that things can have the willingness to do something like the word it will rain, study the linking (Non-action verbs) VS the action verbs. Or save yourself the lesson and understand that as this, you are projecting your probability (The feeling we talked about before) in an inanimate object, (The probability you expect from that inanimate object to "do" the action "based on facts or just a hunch?").
I hope that you can find this useless information useful, I will leave you with a saying to think about, In my time Grammar wasn't a waste of time, but nowadays Grammar is a time of waste, isn't it?