← Public packages
@kentcdodds/groupme
GroupMe REST API helpers for listing groups, reading messages, ranking activity, and preparing relevance-filtered digests for Kody agents.
src/guide.ts
67 lines · 2.9 KB · TypeScriptimport {
GROUPME_ACCESS_TOKEN_SECRET,
GROUPME_API_BASE_URL,
GROUPME_CLIENT_ID_VALUE,
GROUPME_INTEGRATION,
} from './request.ts'
const GROUPME_AUTHORIZE_URL = 'https://oauth.groupme.com/oauth/authorize'
const GROUPME_TOKEN_URL = 'https://oauth.groupme.com/oauth/token'
const GROUPME_APPLICATIONS_URL = 'https://dev.groupme.com/applications/new'
/** Default Kody deployment origin used when none is provided. */
export const DEFAULT_KODY_ORIGIN = 'https://kody.codes'
/**
* Builds the hosted Kody OAuth connect URL for the saved `groupme` integration.
*
* Pass your own deployment origin when this package runs somewhere other than
* the default deployment.
*/
export function getConnectUrl(origin = DEFAULT_KODY_ORIGIN) {
const params = new URLSearchParams({
provider: GROUPME_INTEGRATION,
authorizeUrl: GROUPME_AUTHORIZE_URL,
tokenUrl: GROUPME_TOKEN_URL,
apiBaseUrl: GROUPME_API_BASE_URL,
allowedHosts: 'api.groupme.com,oauth.groupme.com,image.groupme.com',
flow: 'pkce',
dashboardUrl: 'https://dev.groupme.com/applications',
providerSetupInstructions:
'Create a GroupMe application at dev.groupme.com/applications/new. Register the redirect URI shown in the connect wizard. Enter your Client ID on the next screen, complete OAuth, then approve api.groupme.com, oauth.groupme.com, and image.groupme.com for the saved access token.',
})
return `${origin}/connect/oauth?${params.toString()}`
}
/**
* Returns setup guidance for agents and humans.
*/
export function getSetupGuide(origin = DEFAULT_KODY_ORIGIN) {
return {
integration: GROUPME_INTEGRATION,
connectUrl: getConnectUrl(origin),
redirectUri: `${origin}/connect/oauth`,
applicationUrl: GROUPME_APPLICATIONS_URL,
requiredSecrets: [GROUPME_ACCESS_TOKEN_SECRET],
requiredValues: [GROUPME_CLIENT_ID_VALUE],
recommendedApprovedHosts: ['api.groupme.com', 'oauth.groupme.com', 'image.groupme.com'],
notes: [
'GroupMe uses OAuth to mint a user access token sent as the X-Access-Token header.',
'GroupMe documents an implicit-style callback (access_token on the redirect); if the hosted pkce flow stalls, complete OAuth in the browser and save the token from the callback URL as the groupmeAccessToken secret.',
`Reconnect any time with ${origin}/connect/oauth?provider=groupme after the integration is saved.`,
'Use prepare-digest for date-bounded, relevance-filtered message windows before agent summarization.',
],
}
}
/**
* Return GroupMe OAuth setup guidance and connect URL for this deployment.
* @returns Integration metadata, redirect URI, required secrets, and setup notes.
* @example
* import guide from 'kody:@kentcdodds/groupme/guide'
* const info = await guide({ origin: 'https://kody.codes' })
* // => { integration: 'groupme', connectUrl: 'https://.../connect/oauth?...', requiredSecrets: ['groupmeAccessToken'] }
*/
export default async function guideEntrypoint(params: { origin?: string } = {}) {
return getSetupGuide(params.origin ?? DEFAULT_KODY_ORIGIN)
}