我目前正在使用errbot,但我在允许用户输入要与curl命令一起传递的消息方面遇到了麻烦。我的插件看起来如下:
@arg_botcmd('team_key', type=str)
@arg_botcmd('--message' , dest='message', type=str)
def oncall_page(self, msg, team_key=None, message=None):
if team_key in page_list.keys():
team_id = page_list[team_key]
data = {"message_type":"CRITICAL","state_message":"{0}".format(message)}
response = requests.post('https://www.apiurl.com/{0}'.format( team_id), data)
yield "Paging {0} ".format( team_id )
我的问题在于这一行:
data = {"message_type":"CRITICAL","state_message":"{0}".format(message)}
这似乎完全破坏了命令,我希望用户可以执行一个命令,例如"!oncall page team_name --message"
任何帮助将不胜感激:)
答案 0 :(得分:0)
@arg_botcmd('team_key', type=str)
@arg_botcmd('--message' , dest='message', type=str)
def oncall_page(self, msg, team_key=None, message=None):
if team_key in page_list.keys():
team_id = page_list[team_key]
text = str(message)
msg_type = "critical"
data = '{"message_type":"%s", "state_message":"%s"}' % (msg_type, text)
# data = '{"message_type":"critical", "state_message":"%s"}'(text)
URL = 'https://www.apiurl.com/{0}'.format( team_id)
response = requests.post(URL , data)
这是对此的修复!