CISCO spark has exposed few APIs that enable us to send a message to a certain email ID.
Another good part is that, instead of sending the message from a certain user, you can create a Spark Bot and then send a message to the required user from the bot's ID.
If you have a spark account, you can access the tutorials here and have fun.
Creating a bot instructions are available here:
I have tested these APIs and sent messages to myself from the bot's ID using Postman and a simple python script. You can download postman from the following link: https://www.getpostman.com/ and run the apis or run them directly from the interactive Rest API terminal that is present in one of the submenus in the above-mentioned link. You should try various other options as well.
The Python script to send spark message:
import json
import requests
if __name__=="__main__":
sparkUrl="https://api.ciscospark.com/v1/messages"
data = {
"toPersonEmail": "<username>@<domainname>",
"text": "Hello World from my-bot python script. "
}
headers = {
"Content-type": "application/json; charset=utf-8",
"Authorization": "Bearer NDM0MmVjOTItZTM2MS00MmEyLWJiMmEtNDk0MTE1ZjE1NzQzMTE2NDVmZjYtZTdm"
}
r = requests.post(sparkUrl, data=json.dumps(data), headers=headers)
print(r.content)
print(r.status_code, r.reason)
Put the above block inside a method and call it when a certain event occurs and messages are sent.
The next step would be on how to add the bot to a spark room and make it respond to messages that are sent mentioning the bot. This will require you run your bot interactive script to run on a server, create webhooks in spark room for the bot, and code responses that you intend to send in the script.
One example would be like sending a message in a room where the bot is added.
Let the bot name be my-new-bot
@my-new-bot /sayhelloworld
The response from the bot would be:
"Hi <username>@<domainname>, Hello World!!"
If possible, will write about the interactive bot implementation in the future. Until then, have fun. Happy coding! :)
One example would be like sending a message in a room where the bot is added.
Let the bot name be my-new-bot
@my-new-bot /sayhelloworld
The response from the bot would be:
"Hi <username>@<domainname>, Hello World!!"
If possible, will write about the interactive bot implementation in the future. Until then, have fun. Happy coding! :)
Comments
Post a Comment