import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()
from flask import Flask
from flask import request
import requests
from requests_toolbelt import MultipartEncoder
import requests
app = Flask(__name__)
import requests
import json
from datetime import datetime
botEmail = "" # botun email adresi
accessToken = "" # Botun access tokeni
host = "https://api.ciscospark.com/v1/" # CISCO Spark tarafından sunulan hizmetler arasında iletişim kurmak için sağlanan son nokta
server = "localhost" # Web hook sunucu kuruluncaya kadar çalışmaz
port = 4000
headers = {"Authorization": "Bearer %s" % accessToken, "Content-Type": "application/json"}
@app.route('/', methods=['POST'])
def get_tasks():
messageId = request.json.get('data').get('id')
messageDetails = requests.get(host + "messages/" + messageId, headers=headers)
replyForMessages(messageDetails)
return ""
#mesajlara cevap verme metodu
def sendMessage(message, room_id):
payload = {"roomId": room_id, "text": message}
response = requests.request("POST", "https://api.ciscospark.com/v1/messages/", data=json.dumps(payload),
headers=headers)
return response.status_code
#mesajlara görsel cevap verme metodu
def sendMessageWithAttachment(message, filePath, room_id):
payload = {'roomId': room_id,
'text': message,
'files': [filePath]}
response = requests.request("POST", host + "/messages", data=json.dumps(payload), headers=headers)
return response.status_code
#mesajlara senaryoya göre cevap verme
def replyForMessages(response):
responseMessage = response.json().get('text')
toPersonEmail = response.json().get('personEmail')
room_id = response.json().get('roomId')
print
responseMessage
if toPersonEmail != botEmail:
if '#simple#' in responseMessage:
messageString = 'Hello! What can i do for you?'
sendMessage(messageString, room_id)
elif '#photo#' in responseMessage:
filepath = 'https://cdn.pixabay.com/photo/2015/06/17/08/19/dice-812111_1280.png'
sendMessageWithAttachment("lets show the image", filepath, room_id)
else:
#burada bot api si çağırılacak.
#userName = response.json().get('personEmail')
#botartAccessToken = None
#platformName = cisco webex
#userIdentifier = response.json().get('personId')
#timeStamp = response.json().get('created')
messageString = 'Sorry! I was not programmed to answer this question!'
sendMessage(messageString,room_id)
if __name__ == "__main__":
app.run(host=server, port=port, debug=True)
lancelot_1 0 Newbie Poster
rproffitt 2,662 "Nothing to see here." Moderator
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.