Skip to content

Commit

Permalink
keyboards in kik onlye if filled. Enhance logs for sending exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jlmadurga committed Apr 19, 2016
1 parent 26c4e20 commit a8fbd10
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions microbot/models/bot.py
Expand Up @@ -19,6 +19,7 @@
from kik.messages.text import TextMessage
from kik.messages.keyboards import SuggestedResponseKeyboard
from kik.configuration import Configuration
import sys

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -229,8 +230,10 @@ def send_message(self, chat_id, text, keyboard, reply_message=None, user=None):
logger.debug("Message sent OK:(chat:%s,text:%s,parse_mode:%s,disable_preview:%s,reply_keyboard:%s, reply_to_message_id:%s" %
(chat_id, text, parse_mode, disable_web_page_preview, keyboard, reply_to_message_id))
except:
logger.error("Error trying to send message:(chat:%s,text:%s,parse_mode:%s,disable_preview:%s,reply_keyboard:%s, reply_to_message_id:%s" %
(chat_id, text, parse_mode, disable_web_page_preview, keyboard, reply_to_message_id))
exctype, value = sys.exc_info()[:2]

logger.error("Error trying to send message:(chat:%s,text:%s,parse_mode:%s,disable_preview:%s,reply_keyboard:%s, reply_to_message_id:%s): %s:%s" %
(chat_id, text, parse_mode, disable_web_page_preview, keyboard, reply_to_message_id, exctype, value))


@python_2_unicode_compatible
Expand Down Expand Up @@ -316,11 +319,12 @@ def send_message(self, chat_id, text, keyboard, reply_message=None, user=None):
if user:
to = user
msg = TextMessage(to=to, chat_id=chat_id, body=body)

msg.keyboards.append(SuggestedResponseKeyboard(to=to, responses=keyboard))
if keyboard:
msg.keyboards.append(SuggestedResponseKeyboard(to=to, responses=keyboard))
try:
logger.debug("Message to send:(%s)" % msg.to_json())
self._bot.send_messages([msg])
logger.debug("Message sent OK:(%s)" % msg.to_json())
except:
logger.error("Error trying to send message:(%s)" % msg.to_json())
exctype, value = sys.exc_info()[:2]
logger.error("Error trying to send message:(%s): %s:%s" % (msg.to_json(), exctype, value))

0 comments on commit a8fbd10

Please sign in to comment.