import telebot
import mymodule
bot = telebot.TeleBot("YOUR TOKEN")
commands = { # Just commands
'start': 'Start working with bot',
'help': 'Print help',
'resetpass': 'Reset password in SAP'
}
@bot.message_handler(commands=['start'])
def send_welcome(message):
msg = bot.send_message(message.chat.id, 'Welcome to Help Desk !')
help_text = "Following commands are availiable: \n"
for key in commands:
help_text += "/" + key + ": "
help_text += commands[key] + "\n"
bot.send_message(message.chat.id, help_text)
@bot.message_handler(commands=['resetpass'])
def send_welcome(message):
msg = bot.reply_to(message, "Please enter user name")
bot.register_next_step_handler(msg, process_username_for_reset)
def process_username_for_reset(message):
try:
chat_id = message.chat.id
user_name = message.text
if user_name not in mymodule.get_user_list():
bot.send_message(message.chat.id, 'User does not exist !')
else:
mymodule.user_reset_pwd(user_name)
bot.send_message(message.chat.id, 'Pasword reset, new password NewPassword1!')
except Exception as e:
bot.reply_to(message, 'Something wrong ')
@bot.message_handler(content_types=["text"])
def unavailiable_command(message):
msg = bot.send_message(message.chat.id, 'This command does not exist')
if __name__ == '__main__':
bot.polling(none_stop=True)
[connection]
# sap system ip
ashost = XXXXXXXXXXXXX
# sap client id
client = XXX
# sap system number
sysnr = XX
# sap username
user = SERVICEUSER
# sap password
passwd = XXXXXXXX
from pyrfc import Connection, ABAPApplicationError, ABAPRuntimeError, LogonError, CommunicationError
from ConfigParser import ConfigParser
def get_user_list():
try:
config = ConfigParser()
config.read('sapnwrfc.cfg')
params_connection = config._sections['connection']
conn = Connection(**params_connection)
result = conn.call('BAPI_USER_GETLIST')
user_list = result["USERLIST"]
return [x['USERNAME'] for x in user_list]
except CommunicationError:
print u"Could not connect to server."
raise
except LogonError:
print u"Could not log in. Wrong credentials?"
raise
except (ABAPApplicationError, ABAPRuntimeError):
print u"An error occurred."
raise
def user_reset_pwd(user_name):
try:
str_newpass = {'BAPIPWD':'NewPassword1!'}
str_newpassx = {'BAPIPWD':'X'}
config = ConfigParser()
config.read('sapnwrfc.cfg')
params_connection = config._sections['connection']
conn = Connection(**params_connection)
result = conn.call('BAPI_USER_CHANGE',USERNAME = user_name, PASSWORD = str_newpass, PASSWORDX = str_newpassx )
except CommunicationError:
print u"Could not connect to server."
raise
except LogonError:
print u"Could not log in. Wrong credentials?"
raise
except (ABAPApplicationError, ABAPRuntimeError):
print u"An error occurred."
raise
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
7 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |