Skip to content
This repository was archived by the owner on May 27, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ python:
- "2.7"
- "3.6"
install:
- "pip install flake8"
- pip install flake8
script:
- flake8 . --ignore E501,F841,E302
- flake8 .
git:
submodules: false
22 changes: 13 additions & 9 deletions ibm_cloud_functions/iot-pub.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# This function publishes the results from the Watson Assistant service to the Watson IoT platform
import requests


def main(iot_obj):
"""This function publishes the results from the Watson Assistant service
to the Watson IoT platform and subsequently all subscribed devices"""
# import IOT platform credentials
iot_org_id = iot_obj['iot_org_id']
device_id = iot_obj['device_id']
device_type = iot_obj['device_type']
api_token = iot_obj['api_token']
auth = ('use-token-auth', iot_obj['api_token'])
headers = {'Content-Type': 'application/json'}
# extract result from Watson Assistant
payload = {"d": iot_obj['msg']}
# publish Watson Assistant intent/entity pair to Watson IOT platform and subsequently all subscribed devices
requests.post('https://' + iot_org_id + '.messaging.internetofthings.ibmcloud.com:8883/api/v0002/device/types/' + device_type + '/devices/' + device_id + '/events/query', headers={'Content-Type': 'application/json'}, json=payload, auth=('use-token-auth', api_token))
return {"msg": payload}
payload = {'d': iot_obj['msg']}
# publish Watson Assistant intent/entity pair to Watson IOT platform
url = ('https{iot_org_id}.messaging.internetofthings.ibmcloud.com:8883/'
'api/v0002/device/types/{device_type}/devices/{device_id}/events/'
'query'.format(**iot_obj))
requests.post(url, headers=headers, json=payload, auth=auth)
return {'msg': payload}