Created
February 4, 2013 13:41
-
-
Save jerith/4706799 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/go/apps/jsbox/vumi_app.py b/go/apps/jsbox/vumi_app.py | |
| index 6a84175..f5df874 100644 | |
| --- a/go/apps/jsbox/vumi_app.py | |
| +++ b/go/apps/jsbox/vumi_app.py | |
| @@ -5,6 +5,7 @@ | |
| from twisted.internet.defer import inlineCallbacks, returnValue | |
| +from vumi.config import ConfigField | |
| from vumi.application.sandbox import JsSandbox, SandboxResource | |
| from vumi.message import TransportEvent | |
| from vumi import log | |
| @@ -26,6 +27,11 @@ class ConversationConfigResource(SandboxResource): | |
| return self.reply(command, value=value, success=True) | |
| +class JsBoxConfig(JsSandbox.CONFIG_CLASS): | |
| + conversation = ConfigField("Conversation object from message.") | |
| + javascript = ConfigField("Javascript from message.") | |
| + | |
| + | |
| class JsBoxApplication(GoApplicationMixin, JsSandbox): | |
| """ | |
| Application that processes message in a Node.js Javascript Sandbox. | |
| @@ -44,6 +50,7 @@ class JsBoxApplication(GoApplicationMixin, JsSandbox): | |
| And those from :class:`vumi.application.sandbox.JsSandbox`. | |
| """ | |
| + CONFIG_CLASS = JsBoxConfig | |
| SEND_TO_TAGS = frozenset(['default']) | |
| worker_name = 'jsbox_application' | |
| @@ -71,26 +78,31 @@ class JsBoxApplication(GoApplicationMixin, JsSandbox): | |
| return self.get_user_api(api.conversation.user_account.key) | |
| @inlineCallbacks | |
| - def sandbox_protocol_for_message(self, msg_or_event): | |
| - """Return a sandbox protocol for a message or event. | |
| - | |
| - Overrides method from :class:`Sandbox`. | |
| - """ | |
| - if isinstance(msg_or_event, TransportEvent): | |
| - msg = yield self.find_message_for_event(msg_or_event) | |
| - else: | |
| - msg = msg_or_event | |
| + def get_config(self, msg=None): | |
| + if isinstance(msg, TransportEvent): | |
| + msg = yield self.find_message_for_event(msg) | |
| metadata = self.get_go_metadata(msg) | |
| sandbox_id = yield metadata.get_account_key() | |
| conversation = yield metadata.get_conversation() | |
| - config = conversation.metadata['jsbox'] | |
| - javascript = config['javascript'] | |
| + | |
| + config = self.config.copy() | |
| + config.update(conversation.metadata['jsbox']) | |
| + config['sandbox_id'] = sandbox_id | |
| + config['conversation'] = conversation | |
| + | |
| + returnValue(self.CONFIG_CLASS(config)) | |
| + | |
| + def sandbox_protocol_for_message(self, msg, config): | |
| + """Return a sandbox protocol for a message or event. | |
| + | |
| + Overrides method from :class:`Sandbox`. | |
| + """ | |
| api = self.create_sandbox_api(self.resources) | |
| - api.javascript = javascript | |
| - api.conversation = conversation | |
| - protocol = self.create_sandbox_protocol(sandbox_id, api) | |
| - returnValue(protocol) | |
| + api.javascript = config.javascript | |
| + api.conversation = config.conversation | |
| + protocol = self.create_sandbox_protocol(api, config) | |
| + return protocol | |
| def process_command_start(self, batch_id, conversation_type, | |
| conversation_key, msg_options, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment