Sorry to answer so slowly; I'm travelling in Hokkaido without stable internet (Japan, not the most immigration-friendly place in the world but even this may be changing a bit).
Anyway, yes, I must agree that unfortunately social welfare programs and now something like a basic income have a natural conflict with large-scale immigration. Like you I'm also worried about massive AI-powered automation of society. Or, rather, about how to distribute the production of goods and services in a highly-automated society. Maybe the end is nigh for capitalism as we know it? That said, cordoning off countries is certainly not the answer. Why not? Most of our problems are global in nature and therefore require a global "Earth-first" and "Earthlings-first" mindset.
I found myself writing a long-winded answer to you, and don't actually have time to finish it...
But basically, within a rich countries' free movement area, a citizens' basic income should be portable (you get it no matter where you live). So wealthy countries presumably shouldn't worry so much about people from within the area coming to their territories.
Likewise, automation will hit all of these regions simultaneously, give or take say five years. Effects should be the same everywhere.
The crucial thing seems to be that if much labor can be automated, then much of the gains of that automation should be redistributed in a way that can provide for people, at the same time in economic terms keeping up the demand for the automated and non-automated goods and services.
Maybe some kind of robot tax combined with a Land Value Tax (not property tax) could provide this citizens' income. (I'd personally add a greenhouse gas emissions tax, or even simple energy tax.) These could all go toward the citizens' income.
You could take that and go to Stuttgart or Sydney, get a job there, and still have your citizens' income arriving monthly in your account.
Hopefully some day, San Francisco, Stuttgart, Seoul and Sydney would have the same citizens' income, by merging their accounts into a supra-national agreement. At this point, collective action on a global level would be far easier.
What's more, though some people post-automation (well, not that it will ever stop, but at least after the next big wave), some people might be untrainable and become a useless class (as the brilliant Yuval Harari worries), many and probably most people will also be able to use AI and robots to generate income in new ways, or to just use basic human skills which robots won't have (like being a good waiter, cleaning things, selling to others, coaching people, and so on).
Certainly these kinds of ideas aren't the most likely that our societies will choose. But we clearly need ideas now...
For immigration from poorer regions, there is a whole other story, set of problems, and also opportunities. Personally, for immigration to Europe, I'd like to see an EU Migrants Bond. Municipalities that accepted refugees would get an amount of money, borrowed from the European Central Bank, EU sovereign bonds due in say thirty years, to spend on education and settlement of the refugees or migrants. Once the migrants became productive members of society, the increase in revenue (from the increase in economic activity that comes along with increase in population) would fund the repayment of the bonds.
If, in the meantime, automation had taken everything over, then that automation itself could become the source for the repayment of EU Migrant Bonds.
In this way, poor areas which needed employment might even compete for refugees and migrants whom they could educate and integrate. At least that's the idea.
OK, way too much, excuse the length... and also the inchoate nature of the ideas.