When you add the bot to team you will receive the conversation update event - for this event you will receive the group aadid which you can used to get group using graph API.Currently You will receive the group id only when you add the app to team, for other events you will receive the team id. This is y design.
How to get team aadObjectId from payload sent to webhook for MS Teams Bot
We get messages sent to our bot endpoint (webhook).
Payload looks something like:
{ text: '<at>BotName</at> Test Message\n', textFormat: 'plain', attachments: [ { contentType: 'text/html', content: '<div><div><span itemscope="" itemtype="http://schema.skype.com/Mention" itemid="0">BotName</span> Test Message</div>\n</div>' } ], type: 'message', timestamp: '2021-04-30T14:19:16.3736165Z', localTimestamp: '2021-04-30T09:19:16.3736165-05:00', id: '1619792356353', channelId: 'msteams', serviceUrl: 'https://smba.trafficmanager.net/amer/', from: { id: '29:1tNm7r6COQhXBkUSnEMT1mEgMwpEefVDZqN8YwzQ9nhUh3p-tOQOh2P4bojkYYjREBdRNEyUZ82ntmFoauFWGIA', name: 'UserFirst UserLast', aadObjectId: 'UserGuid' }, conversation: { isGroup: true, conversationType: 'channel', tenantId: 'TenantGuid', id: '19:25379995671d49f39998e34fff916e4d@thread.tacv2;messageid=1619792356353' }, recipient: { id: '28:8de65bc3-a5d2-4b1b-836f-3b873777f1a5', name: 'BotName' }, entities: [ { mentioned: [Object], text: '<at>BotName</at>', type: 'mention' }, { locale: 'en-US', country: 'US', platform: 'Web', timezone: 'America/Chicago', type: 'clientInfo' } ], channelData: { teamsChannelId: '19:25379995671d49f39998e34fff916e4d@thread.tacv2', teamsTeamId: '19:25379995671d49f39998e34fff916e4d@thread.tacv2', channel: { id: '19:25379995671d49f39998e34fff916e4d@thread.tacv2' }, team: { id: '19:25379995671d49f39998e34fff916e4d@thread.tacv2' }, tenant: { id: '06445236-3ac4-4dc4-a102-0f77576da83f' } }, locale: 'en-US', localTimezone: 'America/Chicago' }
The payload doesn't contain the aadObject of the team and we haven't been able to find a way to go from anything in the payload to the team aadObjectId