@@ -4,7 +4,7 @@ author: vikasalmal
44description : Learn about message extension search commands for Teams apps, to create a search command through app manifest and manually.
55ms.topic : article
66ms.author : anclear
7- ms.date : 04/14 /2026
7+ ms.date : 04/21 /2026
88ms.localizationpriority : medium
99ms.owner : slamba
1010---
@@ -223,40 +223,40 @@ app.on('message.ext.query', async ({ activity }) => {
223223* [ Sample code reference] ( https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/TeamsSDK/bot-message-extensions/python/bot-message-extensions/main.py )
224224
225225``` python
226- @app.on_message_ext_query
227- async def handle_query (ctx : ActivityContext[MessageExtensionQueryInvokeActivity]):
228- command_id = ctx.activity.value.command_id
229- params = ctx.activity.value.parameters or []
230- query = params[0 ].value if params else " "
231-
232- print (f " Query: command= { command_id} , query= { query} " )
233-
234- # Route to appropriate search
235- if command_id == " wikipediaSearch" :
236- results = await search_wikipedia(query)
237- attachments = [
238- create_attachment(
239- create_wikipedia_card(r),
240- r[' title' ],
241- re.sub(r ' <[ ^ > ] + > ' , ' ' , r.get(' snippet' , ' ' ))
242- )
243- for r in results
244- ]
245-
246- if not attachments:
247- return MessagingExtensionInvokeResponse(
248- compose_extension = MessagingExtensionResult(
249- type = MessagingExtensionResultType.MESSAGE ,
250- text = f " No results found for ' { query} ' "
251- )
252- )
253-
254- return MessagingExtensionInvokeResponse(
255- compose_extension = MessagingExtensionResult(
256- type = MessagingExtensionResultType.RESULT ,
257- attachment_layout = AttachmentLayout .LIST ,
258- attachments = attachments
259- )
226+ @app.on_message_ext_query
227+ async def handle_query (ctx : ActivityContext[MessageExtensionQueryInvokeActivity]):
228+ command_id = ctx.activity.value.command_id
229+ params = ctx.activity.value.parameters or []
230+ query = params[0 ].value if params else " "
231+
232+ print (f " Query: command= { command_id} , query= { query} " )
233+
234+ # Route to appropriate search
235+ if command_id == " wikipediaSearch" :
236+ results = await search_wikipedia(query)
237+ attachments = [
238+ create_attachment(
239+ create_wikipedia_card(r),
240+ r[" title" ],
241+ re.sub(r " <[ ^ > ] + > " , " " , r.get(" snippet" , " " )),
242+ )
243+ for r in results
244+ ]
245+
246+ if not attachments:
247+ return MessagingExtensionResponse(
248+ compose_extension = MessagingExtensionResult(
249+ type = MessagingExtensionResultType.MESSAGE ,
250+ text = f " No results found for ' { query} ' " ,
251+ )
252+ )
253+
254+ return MessagingExtensionResponse(
255+ compose_extension = MessagingExtensionResult(
256+ type = MessagingExtensionResultType.RESULT ,
257+ attachment_layout = MessagingExtensionAttachmentLayout .LIST ,
258+ attachments = attachments,
259+ )
260260 )
261261```
262262
0 commit comments