Skip to content

Commit

Permalink
feat: add default options
Browse files Browse the repository at this point in the history
  • Loading branch information
dubisdev committed Jan 7, 2023
1 parent 153a5db commit f71c6c2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/DirectMessages/DMHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ function withUser() {
const userId = message.sender_id;

const user = await findUser(userId);
if (!user) return sendDirectMessage(userId, getRandomUserNotFoundMessage());
if (!user) return sendDirectMessage(userId, getRandomUserNotFoundMessage(), {
type: 'options',
options: [ { label: '/init' } ]
});

return mainFunc(message, user);
};
Expand Down
31 changes: 28 additions & 3 deletions src/DirectMessages/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ const handleProject: DMHandlerFunction = async (message, user) => {
const { text } = message.message_data;
const projectNum = getProjectNumFromMessage(text);

if (projectNum === null) return sendDirectMessage(userId, TEXTS.INVALID_PROJECT_NUM);
if (projectNum === null) return sendDirectMessage(userId, TEXTS.INVALID_PROJECT_NUM, {
type: 'options',
options: [
{ label: '/project 0' }
]
});

const { todoistToken, todoistProjectId: projectId } = user;
const apiToken = decryptString(todoistToken);
Expand All @@ -77,6 +82,13 @@ const handleProject: DMHandlerFunction = async (message, user) => {
return sendDirectMessage(
userId,
`${TEXTS.INVALID_PROJECT_NUM}Current project is:\n${currentProject}`,
{
type: 'options',
options: [
{ label: '/project 0' },
{ label: `/project ${projects.length - 1}` }
]
}
);
}

Expand Down Expand Up @@ -128,7 +140,13 @@ const handleDefaultDM: DMHandlerFunction = async (message, user) => {

const handleInvalidDM = async (message) => {
const userId = message.sender_id;
sendDirectMessage(userId, generateInvalidDMText(message.sender_name));
sendDirectMessage(userId, generateInvalidDMText(message.sender_name), {
type: 'options',
options: [
{ label: '/help' },
{ label: '/init' },
]
});
};

const handleInit: DMHandlerFunction = async (message) => {
Expand All @@ -138,7 +156,14 @@ const handleInit: DMHandlerFunction = async (message) => {

const handleHelp: DMHandlerFunction = async (message) => {
const userId = message.sender_id;
sendDirectMessage(userId, TEXTS.HELP);
sendDirectMessage(userId, TEXTS.HELP, {
type: 'options',
options: [
{ label: '/init' },
{ label: '/project 0' },
{ label: '/config' },
]
});
};

const handleMain: DMHandlerFunction = async (message: TWDirectMessage, user) => {
Expand Down
5 changes: 3 additions & 2 deletions src/services/twitter-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TwitterApi } from 'twitter-api-v2';
import { MessageCreateQuickReplyV1, TwitterApi } from 'twitter-api-v2';
import Bugsnag from './bugsnag';

const userClient = new TwitterApi({
Expand All @@ -8,11 +8,12 @@ const userClient = new TwitterApi({
accessSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET || '',
});

export const sendDirectMessage = async (userId: string, message: string) => {
export const sendDirectMessage = async (userId: string, message: string, quick_reply?: MessageCreateQuickReplyV1) => {
try {
await userClient.v1.sendDm({
recipient_id: userId,
text: message,
quick_reply
});
} catch (e) {
Bugsnag.notify(e);
Expand Down

0 comments on commit f71c6c2

Please sign in to comment.