Skip to content

Commit

Permalink
Added option to change reply name
Browse files Browse the repository at this point in the history
  • Loading branch information
bostrot committed Sep 20, 2022
1 parent 4464a81 commit c02dc4f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 26 deletions.
30 changes: 16 additions & 14 deletions config/config-sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ owner_id: 'YOUR_TELEGRAM_ID'
spam_time: 5 * 60 * 1000 # time (in MS) in which user may send 5 messages
spam_cant_msg: 5

parse_mode: 'Markdown' # Experimental. Do not change unless you know what you are doing. Options: Markdown/MarkdownV2/HTML
parse_mode: 'MarkdownV2' # Experimental. Do not change unless you know what you are doing. Options: Markdown/MarkdownV2/HTML

allow_private: false # Allow / disallow option for staff to chat privately
direct_reply: false # Set this to true to just forward staff users to a user chat when allow_private
auto_close_tickets: true # Close tickets after answering
anonymous_tickets: true # Include userid in tickets or not
anonymous_replies: true # Include staff member name in response
show_auto_replied: false # Send auto replied msgs to staff chat
show_user_ticket: false # Show ticket id to user

Expand All @@ -26,17 +27,17 @@ dev_mode: true # Enable/disable dev mode
language:
startCommandText: 'Welcome in our support chat! Ask your question here.'
faqCommandText: 'Get this bot at: [github.com](https://github.com/bostrot/telegram-support-bot)'
helpCommandText: "*Available commands:*\n/help\n/faq\n/id"
helpCommandStaffText: "*Available commands:*\n
/start - Get a little introduction\n
/faq - Show frequently asked questions\n
/open - *Staff* Shows a list of open tickets\n
/reopen - *Staff* Reopen a closed ticket\n
/close - *Staff* Reply to a ticket with this to close and unban\n
/clear - *Staff* Closes all tickets\n
/ban - *Staff* Ban a user from the chat\n
helpCommandText: "*Available commands:* /help /faq /id"
helpCommandStaffText: "*Available commands:*
/start - Get a little introduction
/faq - Show frequently asked questions
/open - *Staff* Shows a list of open tickets
/reopen - *Staff* Reopen a closed ticket
/close - *Staff* Reply to a ticket with this to close and unban
/clear - *Staff* Closes all tickets
/ban - *Staff* Ban a user from the chat
/unban - *Staff* Unban a user"
contactMessage: "Thank you for contacting us. We will answer as soon as possible.\n"
contactMessage: "Thank you for contacting us. We will answer as soon as possible. "
blockedSpam: 'You sent quite a number of questions in the last while. Please calm down and wait until staff reviews them.'
ticket: 'Ticket'
closed: 'closed'
Expand Down Expand Up @@ -72,12 +73,13 @@ language:
doesntHelp: 'This does not help.'
automatedReplySent: 'Automated reply was send to the user.'
ticketReopened: 'Ticket reopened.'
regardsGroup: 'Botty Group'

autoreply:
- question: 'install'
answer: "If you want to install the bot, you can use the following link:\n\
[Getting Started](https://github.com/bostrot/telegram-support-bot/wiki/Getting-started)\n\n\
Alternatively you can also use our one-click setup & hosting service:\n\
answer: "If you want to install the bot, you can use the following link: \
[Getting Started](https://github.com/bostrot/telegram-support-bot/wiki/Getting-started) \
Alternatively you can also use our one-click setup & hosting service: \
[Botspace](https://botspace.bostrot.com/)"
- question: 'are you sure?'
answer: 'Yes.'
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ interface Language {
ticketReopened: string;
yourTicketId: string;
helpCommandStaffText: string;
regardsGroup: string;
autoreply: Autoreply[];
}

Expand All @@ -88,6 +89,7 @@ interface Config {
direct_reply: boolean;
auto_close_tickets: boolean;
anonymous_tickets: boolean;
anonymous_replies: boolean;
show_auto_replied: boolean;
signal_enabled: boolean;
signal_number: string;
Expand Down
27 changes: 15 additions & 12 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ import {Context} from './interfaces';

// strict escape
const strictEscape = function(str: string | any[]) {
// let newStr = '';
// const chars = ['[', ']', '(', ')', '_', '*', '~', '`'];
// for (let i = 0; i < str.length; i++) {
// // escape special characters
// if (chars.includes(str[i])) {
// newStr += '\\' + str[i];
// } else {
// newStr += str[i];
// }
// }
// return newStr;
return str.toString();
if (cache.config.parse_mode == 'MarkdownV2'){
let newStr = '';
const chars = ['[', ']', '(', ')', '_', '*', '~', '`'];
for (let i = 0; i < str.length; i++) {
// escape special characters
if (chars.includes(str[i])) {
newStr += '\\' + str[i];
} else {
newStr += str[i];
}
}
return newStr;
} else {
return str.toString();
}
};

// escape special characters
Expand Down
9 changes: 9 additions & 0 deletions src/staff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ function ticketMsg(
message: { text: any; from: { first_name: any } },
) {
const esc: any = middleware.strictEscape;
if (cache.config.anonymous_replies) {
return (
`${cache.config.language.dear} ` +
`${esc(name)},\n\n` +
`${esc(message.text)}\n\n` +
`${cache.config.language.regards}\n` +
`${cache.config.language.regardsGroup}`
);
}
return (
`${cache.config.language.dear} ` +
`${esc(name)},\n\n` +
Expand Down

0 comments on commit c02dc4f

Please sign in to comment.