Beispiel #1
0
    def _handle_group_message(self, msg):
        parts = msg.message_text.split(None, 1)
        if len(parts) != 2:
            return _('Invalid group message: %s') % msg.message_text

        group_id, text = parts

        if not msg.sender:
            return _('The phone number %s is not associated with a Ututi user') % (msg.sender_phone_number)

        group = Group.get(group_id)
        if group is None:
            return _('Invalid group: %s') % group_id

        max_group_members = config.get('sms_max_group_members', 40)
        if len(group.recipients_sms(sender=msg.sender)) > max_group_members:
            return ungettext(
                    'More than %d recipient, cannot send message.',
                    'More than %d recipients, cannot send message.',
                    max_group_members) % max_group_members

        # Send message.
        msg = OutgoingGroupSMSMessage(sender=msg.sender, group=group,
                                      message_text=text)
        meta.Session.add(msg)
        msg.send()

        msg.success = True
        return _('SMS message sent to group %s.') % group_id
Beispiel #2
0
    def send_sms(self, group):
        text = request.params.get('sms_message')
        if not text.strip():
            h.flash(_('Why would you want to send an empty SMS message?'))
            redirect(request.params.get('current_url'))
        cost = sms_cost(text, n_recipients=len(c.group.recipients_sms(sender=c.user)))
        if cost == 0:
            h.flash(_('Nobody received your message... No other group members have confirmed their phone numbers yet. Please encourage them to do so!'))
            redirect(request.params.get('current_url'))
        if c.user.sms_messages_remaining < cost:
            h.flash(_('Not enough SMS credits: you need %d, but you have only %d.')
                    % (cost, c.user.sms_messages_remaining))
            redirect(request.params.get('current_url'))

        c.user.sms_messages_remaining -= cost
        msg = OutgoingGroupSMSMessage(sender=c.user, group=group,
                                      message_text=text)
        meta.Session.add(msg)
        msg.send()
        meta.Session.commit()
        if request.params.has_key('js'):
            return _('SMS reply sent')
        h.flash(_('SMS sent! (%d credits used up, %d remaining)') % (cost, c.user.sms_messages_remaining))
        redirect(request.params.get('current_url'))