1
votes

I'm using the botbuilder-python to build MS Teams bot. Following samples I am able to respond to messages. What I'm struggling with is creating completely new message, without existing activity passed from Teams. I modified some code from the tests (https://github.com/Microsoft/botbuilder-python/blob/62b0512a4dd918fa0d3837207012b31213aaedcc/libraries/botframework-connector/tests/test_conversations.py) but I'm getting:

botbuilder.schema.error_response_py3.ErrorResponseException: (BadSyntax) Could not parse tenant id

What is it, where can I find it (I can fish it out from request but it's not ideal) and how do I pass it? Can anyone point me at any Python samples of creating a new conversation?

1
are you trying to do something like Welcome messages?JJ_Wailes
Not sure what do you mean. I'm integrating client's application with Teams, it needs to send notifications to users at a specific time to nudge them to do something.DrJekyll
Could you please post this query directly on Python SDK Issues page? We had C# & Node.JS code where you could specify tenantId in the conversation parameters but don't have Python sample for this.Wajeed-MSFT
I would recommend starting with the Python EchoBot Sample and working from there. It should give you the framework to start developing your bot.tdurnford
The bot framework requires users to message the bot before the bot is able to message users to prevent spam bots. You can send welcome messages to the user when they join the conversation, but in the Teams channel the user still has to message the bot before the bot can send a welcome message. You can possibly look into proactive messages, but you would need to have a conversation reference which typically comes from an activity.tdurnford

1 Answers

5
votes

I figured it out, just in case anybody else is trying to do the same thing and gets stuck:

to = ChannelAccount(id=to_user_id)

bot_channel = ChannelAccount(id=bot_id)
activity_reply = Activity(type=ActivityTypes.message, channel_id='msteams',from_property=bot_channel,recipient=to,text=message)

credentials=MicrosoftAppCredentials(app_id, app_password)
JwtTokenValidation.authenticate_request(activity_reply, "Authorization", credentials)
# That's where you pass the tenant id
reply_conversation_params=ConversationParameters(bot=bot_channel, members=[to], activity=activity_reply, channel_data={ 'tenant': { 'id': tenant_id } })
connector = ConnectorClient(credentials, base_url='https://smba.trafficmanager.net/uk/')

# Create conversation
conversation = connector.conversations.create_conversation(reply_conversation_params)
# And send it
connector.conversations.send_to_conversation(conversation.id, activity_reply)