Browse Source

add push message neuron

nico 8 years ago
parent
commit
fe23dfc59d

+ 1 - 0
Docs/dev_env_install.md

@@ -28,6 +28,7 @@ pip install jinja
 pip install python-crontab
 pip install cffi
 pip install pygmail
+pip install pushetta
 ```
 
 ### Test your env

+ 6 - 9
brain.yml

@@ -1,15 +1,12 @@
 ---
-  - name: "hello world"
+  - name: "Send push message"
     neurons:
-      - say:
-          message:
-            - "Bonjour monsieur"
-          args:
-            - hour
-            - minute
-
+      - push_message:
+           message: "Message to send"
+           api_key: "my_token_key"
+           channel_name: "my_chanel_name"
     signals:
-      - order: "régle le réveil pour {{ hour }} heures et {{ minute }} minutes"
+      - order: "push message"
 
   - name: "say hello"
     neurons:

+ 1 - 0
install/files/python_requirements.txt

@@ -7,3 +7,4 @@ jinja==1.2
 python-crontab==2.1.1
 cffi==1.8.3
 pygmail==0.0.5.4
+pushetta==1.0.15

+ 30 - 0
neurons/Push_message/Push_message.py

@@ -0,0 +1,30 @@
+from __future__ import absolute_import
+from pushetta import Pushetta
+
+from core.NeuronModule import NeuronModule
+
+
+class Push_message(NeuronModule):
+    """
+    Neuron based on pushetta api. http://www.pushetta.com/
+    """
+
+    def __init__(self, message=None, api_key=None, channel_name=None, **kwargs):
+        """
+        Send a push message to an android phone via Pushetta API
+        :param message: Message to send
+        :param api_key: The Pushetta service secret token
+        :param channel_name: Pushetta channel name
+        :return:
+        """
+        super(Push_message, self).__init__(**kwargs)
+        if message is None:
+            raise NotImplementedError("Pushetta neuron needs message to send")
+
+        if api_key is None:
+            raise NotImplementedError("Pushetta neuron needs api_key")
+        if channel_name is None:
+            raise NotImplementedError("Pushetta neuron needs channel_name")
+
+        p = Pushetta(api_key)
+        p.pushMessage(channel_name, message)

+ 49 - 0
neurons/Push_message/Readme.md

@@ -0,0 +1,49 @@
+# Push notification
+
+## Synopsis
+
+Send broadcast communications to groups of subscribers.
+
+Available client are:
+- Android phone
+- iOS phone/
+- Windows Phone
+- Chrome Browser
+
+This neuron is based on [Pushetta API](http://www.pushetta.com/). 
+You need to [create a free account](http://www.pushetta.com/accounts/signup/) and a chanel before using it.
+You need to install a [client App](http://www.pushetta.com/pushetta-downloads/) on the target device.
+
+## Options
+
+| parameter    | requiered | default | choices | comment                                                                                               |
+|--------------|-----------|---------|---------|-------------------------------------------------------------------------------------------------------|
+| message      | yes       |         |         | Message that will be send to the android phone                                                        |
+| api_key      | yes       |         |         | Token API key availlable from [Pushetta dashboard](http://www.pushetta.com/my/dashboard/) |
+| channel_name | yes       |         |         | Name of the subscribed [channel](http://www.pushetta.com/pushetta-docs/#create)                       |
+
+
+## Return Values
+
+No returned value
+
+
+## Synapses example
+
+The following synapse will send a push message to device that have subscribed to the channel name "my_chanel_name" when you say "push message".
+```
+ - name: "Send push message"
+    neurons:
+      - android_pushetta:
+           message: "Message to send"
+           api_key: "TOEKENEXAMPLE1234"
+           channel_name: "my_chanel_name"
+    signals:
+      - order: "push message"
+```
+
+## Notes
+
+> **Note:** You must install a [client App](http://www.pushetta.com/pushetta-downloads/) on the target device.
+
+> **Note:** You must create a channel an get a token key on [Pushetta website](http://www.pushetta.com/) before using the neuron.

+ 2 - 0
neurons/Push_message/__init__.py

@@ -0,0 +1,2 @@
+from Push_message import Push_message
+

+ 1 - 1
neurons/__init__.py

@@ -6,4 +6,4 @@ from script import Script
 from sleep import Sleep
 from systemdate import Systemdate
 from gmail_checker import Gmail_checker
-
+from Push_message import Push_message

+ 1 - 1
test.py

@@ -14,7 +14,7 @@ from core import OrderAnalyser
 # order = "jarvis régle le réveil pour sept heures et vingt minutes"
 # order = "mais nous de la musique"
 
-order = "arrête la musique"
+order = "push message"
 # order = order.decode('utf-8')
 # print type(order)
 oa = OrderAnalyser(order)