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)

Welcome to Daniweb. Such a post is going to not be a good 1st post as you skipped over the how to post and what to post. I have to write that your 1st post is not unusual but let's get off on the right foot.

Read https://www.daniweb.com/programming/threads/435023/read-this-before-posting-a-question

Yes, I know that folk want to just dump their code on sites and have folk do the work but that's not how it works here. This is more about you sharing the issue or problem and where you are having a problem. If you did want to have others do all the work then you post as a Jobs post along with pay and a full description of what the code should do.

The last time I looked at such a conversion I found IronPython. Look at that with https://www.google.com/search?q=IronPython

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.