Skip to content

Commit

Permalink
add typescript & bot examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna-devv committed Nov 30, 2024
1 parent b43a9e5 commit dbbf127
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,54 @@ As authorization header, you need to provide the `Bearer` token that you set in
curl -X POST http://localhost:8080/refresh \
-H "Authorization: Bearer <your-secret-access-key>"
```

## TypeScript example
```ts
// blahaj.ts
export interface BlahajResponse {
url: string;
}

export async function getBlahaj() {
const blahaj = await fetch(this.url)
.then((r) => r.json())
.catch(() => null) as BlahajResponse | null;

return blahaj;
}

// index.ts
import { getBlahaj } from './blahaj.ts';

const blahaj = await getBlahaj();
console.log(blahaj.url);
```

## JavaScript discord bot example
```js
const { Client, GatewayIntent } = require('discord.js');

const client = new Client({
intents: [
GatewayIntent.GuildMessages,
GatewayIntent.MessageContent,
]
});

client.on('messageCreate', async (message) => {
if (message.content === '!blahaj') {
const blahaj = await fetch('http://localhost:8080')
.then((r) => r.json())
.catch(() => null);

if (!blahaj) {
message.channel.send({ content: 'Failed to get a random blahaj' });
return;
}

message.channel.send({ content: blahaj.url });
}
});

client.login('your-token');
```

0 comments on commit dbbf127

Please sign in to comment.