def get_channel(self, request, channel_id): '''Return the channel configuration and a nested status object''' channel = yield Channel.from_id( self.redis, self.config, channel_id, self.service) resp = yield channel.status() returnValue(response( request, 'channel found', resp))
def modify_channel(self, request, body, channel_id): '''Mondify the channel configuration''' channel = yield Channel.from_id( self.redis, self.config, channel_id, self.service) resp = yield channel.update(body) returnValue(response( request, 'channel updated', resp))
def modify_channel(self, request, body, channel_id): '''Mondify the channel configuration''' channel = yield Channel.from_id( self.redis, self.config, channel_id, self.service, self.plugins) resp = yield channel.update(body) returnValue(response( request, 'channel updated', resp))
def restart_channel(self, request, channel_id): '''Restart a channel.''' channel = yield Channel.from_id( self.redis, self.config, channel_id, self.service, self.plugins) yield channel.stop() yield channel.start(self.service) returnValue(response(request, 'channel restarted', {}))
def validate_router_config(cls, api, config): try: config = FromAddressRouterConfig(config) except ConfigError as e: raise InvalidRouterConfig(e.message) channel_id = str(config.channel) try: channel = yield Channel.from_id( api.redis, api.config, channel_id, api.service, api.plugins) except ChannelNotFound: raise InvalidRouterConfig( "Channel {} does not exist".format(channel_id)) if channel.has_destination: raise InvalidRouterConfig( "Channel {} already has a destination specified".format( channel_id)) # Check that no other routers are listening to this channel def check_router_channel(router): channel = router.get('config', {}).get('channel', None) if channel == channel_id: raise InvalidRouterConfig( "Router {} is already routing channel {}".format( router['id'], channel_id)) routers = yield api.router_store.get_router_list() routers = yield gatherResults([ api.router_store.get_router_config(r) for r in routers]) for router in routers: check_router_channel(router)
def get_channel(self, request, channel_id): '''Return the channel configuration and a nested status object''' channel = yield Channel.from_id( self.redis, self.config, channel_id, self.service, self.plugins) resp = yield channel.status() returnValue(response( request, 'channel found', resp))
def send_message(self, request, body, channel_id): '''Send an outbound (mobile terminated) message''' if 'to' not in body and 'reply_to' not in body: raise ApiUsageError('Either "to" or "reply_to" must be specified') if 'to' in body and 'reply_to' in body: raise ApiUsageError( 'Only one of "to" and "reply_to" may be specified') if 'from' in body and 'reply_to' in body: raise ApiUsageError( 'Only one of "from" and "reply_to" may be specified') channel = yield Channel.from_id(self.redis, self.config, channel_id, self.service, self.plugins) if 'to' in body: msg = yield channel.send_message(self.message_sender, self.outbounds, body) else: msg = yield channel.send_reply_message(self.message_sender, self.outbounds, self.inbounds, body) yield self.message_rate.increment(channel_id, 'outbound', self.config.metric_window) returnValue(response(request, 'message sent', msg))
def delete_channel(self, request, channel_id): '''Delete the channel''' channel = yield Channel.from_id(self.redis, self.config, channel_id, self.service, self.plugins) yield channel.stop() yield channel.delete() returnValue(response(request, 'channel deleted', {}))
def send_message(self, request, body, channel_id): '''Send an outbound (mobile terminated) message''' if 'to' not in body and 'reply_to' not in body: raise ApiUsageError( 'Either "to" or "reply_to" must be specified') if 'to' in body and 'reply_to' in body: raise ApiUsageError( 'Only one of "to" and "reply_to" may be specified') if 'from' in body and 'reply_to' in body: raise ApiUsageError( 'Only one of "from" and "reply_to" may be specified') channel = yield Channel.from_id( self.redis, self.config, channel_id, self.service, self.plugins) if 'to' in body: msg = yield channel.send_message( self.message_sender, self.outbounds, body) else: msg = yield channel.send_reply_message( self.message_sender, self.outbounds, self.inbounds, body) yield self.message_rate.increment( channel_id, 'outbound', self.config.metric_window) returnValue(response(request, 'message sent', msg))
def delete_channel(self, request, channel_id): '''Delete the channel''' channel = yield Channel.from_id( self.redis, self.config, channel_id, self.service) yield channel.stop() yield channel.delete() returnValue(response( request, 'channel deleted', {}))
def get_logs(self, request, channel_id): '''Get the last N logs for a channel, sorted reverse chronologically.''' n = request.args.get('n', None) if n is not None: n = int(n[0]) channel = yield Channel.from_id( self.redis, self.config, channel_id, self.service, self.plugins) logs = yield channel.get_logs(n) returnValue(response(request, 'logs retrieved', logs))
def send_message(self, request, body, channel_id): '''Send an outbound (mobile terminated) message''' if 'to' not in body and 'reply_to' not in body: raise ApiUsageError( 'Either "to" or "reply_to" must be specified') channel = yield Channel.from_id( self.redis, self.config, channel_id, self.service, self.plugins) if 'reply_to' in body: msg = yield channel.send_reply_message( self.message_sender, self.outbounds, self.inbounds, body, allow_expired_replies=self.config.allow_expired_replies) else: msg = yield channel.send_message( self.message_sender, self.outbounds, body) yield self.message_rate.increment( channel_id, 'outbound', self.config.metric_window) returnValue(response( request, 'message submitted', msg, code=http.CREATED))
def create_channel_from_id(self, redis, config, id, service): '''Creates an existing channel given the channel id''' config = yield self.create_channel_config(**config) channel = yield Channel.from_id(redis, config, id, service) returnValue(channel)