Skip to content

Commit

Permalink
fix: fix bot-me search limitations (#12925)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yimin-Jin authored Dec 17, 2024
1 parent e3e79e0 commit 4574dd1
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
12 changes: 12 additions & 0 deletions templates/js/m365-message-extension/src/searchApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ class SearchApp extends TeamsActivityHandler {
// Search.
async handleTeamsMessagingExtensionQuery(context, query) {
const searchQuery = query.parameters[0].value;

// Due to npmjs search limitations, do not search if input length < 2
if (searchQuery.length < 2) {
return {
composeExtension: {
type: "result",
attachmentLayout: "list",
attachments: [],
},
};
}

const response = await axios.get(
`http://registry.npmjs.com/-/v1/search?${querystring.stringify({
text: searchQuery,
Expand Down
12 changes: 12 additions & 0 deletions templates/js/message-extension-copilot/src/searchApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ class SearchApp extends TeamsActivityHandler {
// Search.
async handleTeamsMessagingExtensionQuery(context, query) {
const searchQuery = query.parameters[0].value;

// Due to npmjs search limitations, do not search if input length < 2
if (searchQuery.length < 2) {
return {
composeExtension: {
type: "result",
attachmentLayout: "list",
attachments: [],
},
};
}

const response = await axios.get(
`http://registry.npmjs.com/-/v1/search?${querystring.stringify({
text: searchQuery,
Expand Down
12 changes: 12 additions & 0 deletions templates/js/message-extension/src/teamsBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ class TeamsBot extends TeamsActivityHandler {
// Search.
async handleTeamsMessagingExtensionQuery(context, query) {
const searchQuery = query.parameters[0].value;

// Due to npmjs search limitations, do not search if input length < 2
if (searchQuery.length < 2) {
return {
composeExtension: {
type: "result",
attachmentLayout: "list",
attachments: [],
},
};
}

const response = await axios.get(
`http://registry.npmjs.com/-/v1/search?${querystring.stringify({
text: searchQuery,
Expand Down
12 changes: 12 additions & 0 deletions templates/ts/m365-message-extension/src/searchApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ export class SearchApp extends TeamsActivityHandler {
query: MessagingExtensionQuery
): Promise<MessagingExtensionResponse> {
const searchQuery = query.parameters[0].value;

// Due to npmjs search limitations, do not search if input length < 2
if (searchQuery.length < 2) {
return {
composeExtension: {
type: "result",
attachmentLayout: "list",
attachments: [],
},
};
}

const response = await axios.get(
`http://registry.npmjs.com/-/v1/search?${querystring.stringify({
text: searchQuery,
Expand Down
12 changes: 12 additions & 0 deletions templates/ts/message-extension-copilot/src/searchApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ export class SearchApp extends TeamsActivityHandler {
query: MessagingExtensionQuery
): Promise<MessagingExtensionResponse> {
const searchQuery = query.parameters[0].value;

// Due to npmjs search limitations, do not search if input length < 2
if (searchQuery.length < 2) {
return {
composeExtension: {
type: "result",
attachmentLayout: "list",
attachments: [],
},
};
}

const response = await axios.get(
`http://registry.npmjs.com/-/v1/search?${querystring.stringify({
text: searchQuery,
Expand Down
12 changes: 12 additions & 0 deletions templates/ts/message-extension/src/teamsBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ export class TeamsBot extends TeamsActivityHandler {
query: MessagingExtensionQuery
): Promise<MessagingExtensionResponse> {
const searchQuery = query.parameters[0].value;

// Due to npmjs search limitations, do not search if input length < 2
if (searchQuery.length < 2) {
return {
composeExtension: {
type: "result",
attachmentLayout: "list",
attachments: [],
},
};
}

const response = await axios.get(
`http://registry.npmjs.com/-/v1/search?${querystring.stringify({
text: searchQuery,
Expand Down

0 comments on commit 4574dd1

Please sign in to comment.