Skip to content

Instantly share code, notes, and snippets.

@sgr-ksmt sgr-ksmt/sample.ts
Created Nov 15, 2018

Embed
What would you like to do?
Issue Dynamic Link via Cloud Functions
import * as functions from 'firebase-functions'
import * as request from 'request-promise-native'
export namespace IssueDynamicLink {
export interface Request {
params: DynamicLinkParameters
}
export interface Response {
url: string
}
}
export interface DynamicLinkParameters {
link: string
iosInfo?: {
iosBundleId?: BundleIdentifier
iosFallbackLink?: string
iosAppStoreId?: AppID
}
socialMetaTagInfo?: {
socialTitle?: string
socialDescription?: string
socialImageLink?: string
}
}
export const onCalledIssueDynamicLink = functions.https.onCall(async (data, context) => {
try {
return issueDynamicLink(data, context)
} catch (error) {
console.error(error)
throw error
}
})
const issueDynamicLink = async (data: IssueDynamicLink.Request, context: CallableContext) => {
const json = {
'dynamicLinkInfo': {
'dynamicLinkDomain': 'example.page.link',
'link': data.params.link,
'iosInfo': data.params.iosInfo,
'socialMetaTagInfo': data.params.socialMetaTagInfo
},
'suffix': {
'option': 'SHORT'
}
}
const options: request.Options = {
uri: `https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=${API_KEY}`,
method: 'POST',
headers: {
'content-type': 'application/json'
},
json: JSON.parse(JSON.stringify(json))
}
const response = await request(options)
return { url: response.shortLink }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.