Twitch bot deployment work (#892)
* Point at production Twitch bot endpoint * Move Twitch endpoints into env config
This commit is contained in:
		
							parent
							
								
									65166f2fcb
								
							
						
					
					
						commit
						39119a3419
					
				|  | @ -16,4 +16,6 @@ export const DEV_CONFIG: EnvConfig = { | ||||||
|   cloudRunId: 'w3txbmd3ba', |   cloudRunId: 'w3txbmd3ba', | ||||||
|   cloudRunRegion: 'uc', |   cloudRunRegion: 'uc', | ||||||
|   amplitudeApiKey: 'fd8cbfd964b9a205b8678a39faae71b3', |   amplitudeApiKey: 'fd8cbfd964b9a205b8678a39faae71b3', | ||||||
|  |   // this is Phil's deployment
 | ||||||
|  |   twitchBotEndpoint: 'https://king-prawn-app-5btyw.ondigitalocean.app', | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ export type EnvConfig = { | ||||||
|   domain: string |   domain: string | ||||||
|   firebaseConfig: FirebaseConfig |   firebaseConfig: FirebaseConfig | ||||||
|   amplitudeApiKey?: string |   amplitudeApiKey?: string | ||||||
|  |   twitchBotEndpoint?: string | ||||||
| 
 | 
 | ||||||
|   // IDs for v2 cloud functions -- find these by deploying a cloud function and
 |   // IDs for v2 cloud functions -- find these by deploying a cloud function and
 | ||||||
|   // examining the URL, https://[name]-[cloudRunId]-[cloudRunRegion].a.run.app
 |   // examining the URL, https://[name]-[cloudRunId]-[cloudRunRegion].a.run.app
 | ||||||
|  | @ -66,6 +67,7 @@ export const PROD_CONFIG: EnvConfig = { | ||||||
|     appId: '1:128925704902:web:f61f86944d8ffa2a642dc7', |     appId: '1:128925704902:web:f61f86944d8ffa2a642dc7', | ||||||
|     measurementId: 'G-SSFK1Q138D', |     measurementId: 'G-SSFK1Q138D', | ||||||
|   }, |   }, | ||||||
|  |   twitchBotEndpoint: 'https://twitch-bot-nggbo3neva-uc.a.run.app', | ||||||
|   cloudRunId: 'nggbo3neva', |   cloudRunId: 'nggbo3neva', | ||||||
|   cloudRunRegion: 'uc', |   cloudRunRegion: 'uc', | ||||||
|   adminEmails: [ |   adminEmails: [ | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| import { PrivateUser, User } from 'common/user' | import { PrivateUser, User } from 'common/user' | ||||||
| import { generateNewApiKey } from '../api/api-key' | import { generateNewApiKey } from '../api/api-key' | ||||||
| 
 | import { ENV_CONFIG } from 'common/envs/constants' | ||||||
| const TWITCH_BOT_PUBLIC_URL = 'https://king-prawn-app-5btyw.ondigitalocean.app' // TODO: Add this to env config appropriately
 |  | ||||||
| 
 | 
 | ||||||
| async function postToBot(url: string, body: unknown) { | async function postToBot(url: string, body: unknown) { | ||||||
|   const result = await fetch(url, { |   const result = await fetch(url, { | ||||||
|  | @ -21,13 +20,16 @@ export async function initLinkTwitchAccount( | ||||||
|   manifoldUserID: string, |   manifoldUserID: string, | ||||||
|   manifoldUserAPIKey: string |   manifoldUserAPIKey: string | ||||||
| ): Promise<[string, Promise<{ twitchName: string; controlToken: string }>]> { | ): Promise<[string, Promise<{ twitchName: string; controlToken: string }>]> { | ||||||
|   const response = await postToBot(`${TWITCH_BOT_PUBLIC_URL}/api/linkInit`, { |   const response = await postToBot( | ||||||
|  |     `${ENV_CONFIG.twitchBotEndpoint}/api/linkInit`, | ||||||
|  |     { | ||||||
|       manifoldID: manifoldUserID, |       manifoldID: manifoldUserID, | ||||||
|       apiKey: manifoldUserAPIKey, |       apiKey: manifoldUserAPIKey, | ||||||
|       redirectURL: window.location.href, |       redirectURL: window.location.href, | ||||||
|   }) |     } | ||||||
|  |   ) | ||||||
|   const responseFetch = fetch( |   const responseFetch = fetch( | ||||||
|     `${TWITCH_BOT_PUBLIC_URL}/api/linkResult?userID=${manifoldUserID}` |     `${ENV_CONFIG.twitchBotEndpoint}/api/linkResult?userID=${manifoldUserID}` | ||||||
|   ) |   ) | ||||||
|   return [response.twitchAuthURL, responseFetch.then((r) => r.json())] |   return [response.twitchAuthURL, responseFetch.then((r) => r.json())] | ||||||
| } | } | ||||||
|  | @ -50,15 +52,18 @@ export async function updateBotEnabledForUser( | ||||||
|   botEnabled: boolean |   botEnabled: boolean | ||||||
| ) { | ) { | ||||||
|   if (botEnabled) { |   if (botEnabled) { | ||||||
|     return postToBot(`${TWITCH_BOT_PUBLIC_URL}/registerchanneltwitch`, { |     return postToBot(`${ENV_CONFIG.twitchBotEndpoint}/registerchanneltwitch`, { | ||||||
|       apiKey: privateUser.apiKey, |       apiKey: privateUser.apiKey, | ||||||
|     }).then((r) => { |     }).then((r) => { | ||||||
|       if (!r.success) throw new Error(r.message) |       if (!r.success) throw new Error(r.message) | ||||||
|     }) |     }) | ||||||
|   } else { |   } else { | ||||||
|     return postToBot(`${TWITCH_BOT_PUBLIC_URL}/unregisterchanneltwitch`, { |     return postToBot( | ||||||
|  |       `${ENV_CONFIG.twitchBotEndpoint}/unregisterchanneltwitch`, | ||||||
|  |       { | ||||||
|         apiKey: privateUser.apiKey, |         apiKey: privateUser.apiKey, | ||||||
|     }).then((r) => { |       } | ||||||
|  |     ).then((r) => { | ||||||
|       if (!r.success) throw new Error(r.message) |       if (!r.success) throw new Error(r.message) | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
|  | @ -66,10 +71,10 @@ export async function updateBotEnabledForUser( | ||||||
| 
 | 
 | ||||||
| export function getOverlayURLForUser(privateUser: PrivateUser) { | export function getOverlayURLForUser(privateUser: PrivateUser) { | ||||||
|   const controlToken = privateUser?.twitchInfo?.controlToken |   const controlToken = privateUser?.twitchInfo?.controlToken | ||||||
|   return `${TWITCH_BOT_PUBLIC_URL}/overlay?t=${controlToken}` |   return `${ENV_CONFIG.twitchBotEndpoint}/overlay?t=${controlToken}` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function getDockURLForUser(privateUser: PrivateUser) { | export function getDockURLForUser(privateUser: PrivateUser) { | ||||||
|   const controlToken = privateUser?.twitchInfo?.controlToken |   const controlToken = privateUser?.twitchInfo?.controlToken | ||||||
|   return `${TWITCH_BOT_PUBLIC_URL}/dock?t=${controlToken}` |   return `${ENV_CONFIG.twitchBotEndpoint}/dock?t=${controlToken}` | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user