Skip to content

Commit

Permalink
feat(sdk): added method to delete shortlink
Browse files Browse the repository at this point in the history
  • Loading branch information
allardy committed Nov 1, 2018
1 parent fc29a45 commit 13f97dd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/bp/core/api.ts
Expand Up @@ -31,6 +31,9 @@ const http = (httpServer: HTTPServer): typeof sdk.http => {
createShortLink(name: string, destination: string, params?: any): void {
httpServer.createShortLink(name, destination, params)
},
deleteShortLink(name: string): void {
httpServer.deleteShortLink(name)
},
createRouterForBot(routerName: string, options?: sdk.RouterOptions): any {
const defaultRouterOptions = { checkAuthentication: true, enableJsonBodyParser: true }
return httpServer.createRouterForBot(routerName, options || defaultRouterOptions)
Expand Down
4 changes: 4 additions & 0 deletions src/bp/core/routers/shortlinks.ts
Expand Up @@ -42,4 +42,8 @@ export class ShortLinksRouter implements CustomRouter {
const query = params ? `?${qs.stringify(params)}` : ''
this.shortlinks.set(name, `${destination}${query}`)
}

deleteShortLink(name: string) {
this.shortlinks.delete(name)
}
}
4 changes: 4 additions & 0 deletions src/bp/core/server.ts
Expand Up @@ -157,6 +157,10 @@ export default class HTTPServer {
this.shortlinksRouter.createShortLink(name, destination, params)
}

deleteShortLink(name: string) {
this.shortlinksRouter.deleteShortLink(name)
}

async getAxiosConfigForBot(botId: string): Promise<AxiosBotConfig> {
const botpressConfig = await this.configProvider.getBotpressConfig()
const config = botpressConfig.httpServer
Expand Down
7 changes: 7 additions & 0 deletions src/bp/sdk/botpress.d.ts
Expand Up @@ -535,6 +535,13 @@ declare module 'botpress/sdk' {
*/
export function createShortLink(name: string, destination: string, params?: any): void

/**
* Delete any previously created short link
*
* @param name - The name of the link to remove
*/
export function deleteShortLink(name): void

/**
* Create a new router for a module. Once created, use them to register new endpoints. Routers created
* with this method are accessible via the url /api/ext/{routernName}
Expand Down

0 comments on commit 13f97dd

Please sign in to comment.