-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update phrases, update
/start
command, add /menu
command
- Loading branch information
Showing
8 changed files
with
131 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import views from '~/bot/handlers/views' | ||
import { handler } from '~/bot/handlers' | ||
import filters from '~/bot/filters' | ||
import { TelegramNotLinkedToInnohassleAccountError } from '~/domain/errors' | ||
import { InnohassleLoginButton } from '~/bot/login-button' | ||
|
||
export default handler((composer) => { | ||
composer | ||
.command('start') | ||
.filter(filters.pm) | ||
.use(async (ctx) => { | ||
let authorized | ||
try { | ||
authorized = await ctx.domain.isUserAuthorized(ctx.from.id) | ||
} catch (error) { | ||
authorized = false | ||
if (error instanceof TelegramNotLinkedToInnohassleAccountError) { | ||
// ignore | ||
} else { | ||
ctx.logger.error({ | ||
msg: 'failed to check whether user is authorized', | ||
error: error, | ||
}) | ||
} | ||
} | ||
|
||
let content | ||
if (authorized) { | ||
content = await views.main.render(ctx, {}) | ||
} else { | ||
content = ( | ||
<> | ||
{ctx.t['WelcomeMessage.Unauthorized']} | ||
<keyboard> | ||
<InnohassleLoginButton | ||
loginUrl={ctx.config.innohassle.telegramLoginUrl} | ||
loginBotUsername={ctx.config.innohassle.telegramBotUsername} | ||
returnBotUsername={ctx.me.username} | ||
> | ||
{ctx.t['Buttons.LoginWithInnohassle']} | ||
</InnohassleLoginButton> | ||
</keyboard> | ||
</> | ||
) | ||
} | ||
|
||
await ctx.send(content).to(ctx.chat.id) | ||
}) | ||
}) |
27 changes: 12 additions & 15 deletions
27
backend/src/bot/handlers/root.ts → backend/src/bot/handlers/root.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export function InnohassleLoginButton({ | ||
loginUrl: loginUrlStr, | ||
loginBotUsername, | ||
returnBotUsername, | ||
children, | ||
}: { | ||
loginUrl: string | ||
loginBotUsername: string | ||
returnBotUsername: string | ||
children: string | ||
}) { | ||
const loginUrl = new URL(loginUrlStr) | ||
loginUrl.searchParams.set('bot', `${returnBotUsername}?start=_`) | ||
return ( | ||
<button | ||
loginUrl={{ | ||
url: loginUrl.toString(), | ||
bot_username: loginBotUsername, | ||
}} | ||
> | ||
{children} | ||
</button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.