Skip to content

Instantly share code, notes, and snippets.

@dudanogueira
Created December 13, 2022 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dudanogueira/ec09911b6a6f7e53f833635fc4407ed8 to your computer and use it in GitHub Desktop.
Save dudanogueira/ec09911b6a6f7e53f833635fc4407ed8 to your computer and use it in GitHub Desktop.
Petry POC
import {
IAppAccessors,
IConfigurationExtend,
ILogger,
} from "@rocket.chat/apps-engine/definition/accessors";
import { App } from "@rocket.chat/apps-engine/definition/App";
import { IAppInfo } from "@rocket.chat/apps-engine/definition/metadata";
import {
IHttp,
IModify,
IRead,
} from "@rocket.chat/apps-engine/definition/accessors";
import {
ISlashCommand,
SlashCommandContext,
} from "@rocket.chat/apps-engine/definition/slashcommands";
import { AuthProvider, AuthProviderCallback, Client, Options } from "@microsoft/microsoft-graph-client";
import "isomorphic-fetch"
export class PetryPocApp extends App {
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
super(info, logger, accessors);
}
public async extendConfiguration(configuration: IConfigurationExtend) {
configuration.slashCommands.provideSlashCommand(new PetryPocCommand()); // [2]
}
}
export class PetryPocCommand implements ISlashCommand {
public command = "petry"; // [1]
public i18nParamsExample = "petrya";
public i18nDescription = "petrya";
public providesPreview = false;
public async executor(
context: SlashCommandContext,
read: IRead,
modify: IModify,
http: IHttp
): Promise<void> {
console.log("executing MS stuff");
// Some callback function
const authProvider: AuthProvider = (callback: AuthProviderCallback) => {
// Your logic for getting and refreshing accessToken
// Error should be passed in case of error while authenticating
// accessToken should be passed upon successful authentication
callback('error!', 'some-access-token');
};
let options: Options = {
authProvider,
};
const client = Client.init(options);
console.log("CLIENT!!!", client )
try {
let userDetails = await client.api("/me").get();
console.log("USERDETAILS HERE!!! ", userDetails);
} catch (error) {
console.log("ERROR HERE!! ", error);
throw error;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment