예제 #1
0
 def start(self):
     depName = self.db.flow.get('dep_name')
     interest = self.db.flow.get('interest')
     depName = str(depName)
     interest = str(interest)
     depName_ = depName[0:4].upper()
     lists = self.db.table('course_data_1').filter(subject=depName_)
     courses = []
     messages = []
     if not interest:
         message = "you should input interest"
         messages.append(message)
     else:
         for courses in lists:
             if interest.lower() in courses['description'].lower():
                 title = "Course Title: " + str(courses.get('title'))
                 location = "Location:" + str(courses.get('location'))
                 find = location.find('DCH')
                 if find > -1:
                     imgsrc = self.db.table('img_data_1').filter(
                         location="DCH")[0].get('imgsrc')
                 find = location.find('HUM')
                 if find > -1:
                     imgsrc = self.db.table('img_data_1').filter(
                         location="HUM")[0].get('imgsrc')
                 find = location.find('HEB')
                 if find > -1:
                     imgsrc = self.db.table('img_data_1').filter(
                         location="HEB")[0].get('imgsrc')
                 find = location.find('HRG')
                 if find > -1:
                     imgsrc = self.db.table('img_data_1').filter(
                         location="HRG")[0].get('imgsrc')
                 description = "Discription:" + str(
                     courses.get('description'))
                 buttons = [
                     Button(text="This course is great!",
                            action="course_rock"),
                     Button(text="This course is not so great!",
                            action="course_sucks"),
                     Button(text="I'm going to the class now",
                            action="cal_distance")
                 ]
                 card = Card(
                     title=title,
                     text=location + '\n' + '\n' + description,
                     image_url=imgsrc,
                     buttons=buttons,
                 )
                 message = self.create_message(card=card)
                 messages.append(message)
     return self.respond(messages=messages, action="next")
예제 #2
0
 def start(self):
     # TODO: get this information from the fictional Timecast API
     text = (
         "I see you're on our Basic package. I can upgrade you to Gold for "
         "$20/mo or VIP for an additional $40/mo. Are you interested in "
         "one of these upgrades? Or can I help in some other way?")
     buttons = [
         Button(text='Upgrade to Gold'),
         Button(text='Upgrade to VIP')
     ]
     card = TextWithButtons(text=text, buttons=buttons)
     message = self.create_message(card=card)
     return self.respond(message=message, action="next")
예제 #3
0
    def start(self):
        
        # Getting color details and selected matching harmony 
        api_host = host()
        harmony = self.properties['harmony']
        color = str(self.db.user.get('color'))       
        URL = '/' + harmony + '?name=' + color
        response = requests.get(api_host + URL)
        response = response.json()['result'][0]
        color_names = []
        color_img = []
        
        # Getting color names and color images of matching colors in a list 
        for color in response:
            color_names.append(response[color]['Name'])
            color_img.append(response[color]['imgURL'])
    
        ppg_url = api_host + '/colors?name='
        url_response = []
        
        # Getting details of each color
        for name in color_names:
            response =  requests.get(ppg_url + name)
            response = response.json()['result']
            url_response.append(response)
        
        elements = []
        
        # Creating Cards of matching colors
        for i in range(0, len(color_names)):
            buttons = [
                Button(text="Get Details",flow="color_details",data={'colorName': color_names[i]}),
                Button(text="Go to PPG", url=more_info(url_response[i]['Color Name'],url_response[i]['Color Number'],url_response[i]['Collection Name']))
            ]
     
            element = Card(title=color_names[i],
                          image_url=url_response[i]['imgURL'],
                          buttons=buttons)
            
            elements.append(element)

        # Creating reply msg 
        card = Cards(elements=elements)
        message= self.create_message(card=card)
        text = 'We found that these colors match with {}: '.format(str(self.db.user.get('color'))       )
        reply_text = self.create_message(text=text)
        message = [reply_text,message]
        
        return self.respond(messages=message,action="next")
예제 #4
0
    def start(self):
        # instantiate the card
        text = 'What is your favorite elelphant?'
        buttons = [
          Button(text='African Elephant'),
          Button(text='Asian Elephant'),
          Button(text='Woolly Mammoth')
        ]
        card = TextWithButtons(text=text, buttons=buttons, mode="quick_reply")

        # create the message (note the `card` rather than `text`)
        message = self.create_message(card=card)

        # respond as you normally would
        return self.respond(message=message, action="next")
예제 #5
0
    def start(self):
        
        uid = self.db.flow.get('uuid')
        userId = self.db.user.id
        cardId = self.db.flow.get('cardId')
        
        print uid
        print userId
        print cardId
        # Single button
        buttons = [
            Button(text="Pay", url="http://ec2.urkei.com:9091/v1/giftbot/stripe/card?cardId="+cardId+"&uuid="+uid+"&userId="+userId)
        ]
        # construct a list of cards (they are `generic` template in Messenger)
        elements = []
        element = Card(
            title="Stripe", text="Gateway", image_url="http://ec2.urkei.com:9091/v1/giftbot/stripe.png",
            buttons=buttons
        )
        elements.append(element)

        # `Cards` is a multi card element in Messenger
        card = Cards(elements=elements)

        # create the message (note the `card` rather than `text`)
        message = self.create_message(card=card)

        # respond as you normally would
        return self.respond(message=message, action="next")
예제 #6
0
    def start(self):
        # instantiate the card
        title = "Elephants are big"
        text = "They are really big sometimes."
        image_url = "http://bit.ly/1NPO0xx"
        buttons = [Button(text='Agreed'), Button(text='Whales are bigger')]
        card = Card(title=title,
                    text=text,
                    image_url=image_url,
                    buttons=buttons)

        # create the message (note the `card` rather than `text`)
        message = self.create_message(card=card)

        # respond as you normally would
        return self.respond(message=message, action="next")
예제 #7
0
    def start(self):

        # From a selected color, get details in json
        color = str(self.db.flow.get('colorName'))
        self.db.user.set('color', color)
        URL = '/colors?name=' + color
        api_host = host()
        response = requests.get(api_host + URL)
        response = response.json()['result']

        # Organizing detail info to display Color Number, RGB, Desc, Image
        name = color
        number = response['Color Number']
        r, g, b = str(response['R']), str(response['G']), str(response['B'])
        desc = response['Color Description']
        colName = response['Collection Name']
        imgURL = response['imgURL']
        ppg_url = more_info(name, number, colName)
        buttons = [Button(text="Go to PPG", url=ppg_url)]
        card = Card(image_url=imgURL, title=name, buttons=buttons)

        # creating reply msg
        the_card = self.create_message(card=card)
        text = 'Description: ' + desc + '\n' + 'RGB: ( ' + r + ', ' + g + ', ' + b + ' )' + '\n' + 'Color Number: ' + number
        reply_text = self.create_message(text=text)

        message = [the_card, reply_text]
        return self.respond(messages=message, action="next")
예제 #8
0
    def start(self):

        # From user color, change to color(s) based on selected harmony
        api_host = host()
        harmony = self.properties['harmony']
        color = str(self.db.user.get('color'))
        URL = '/' + harmony + '?name=' + color
        response = requests.get(api_host + URL)
        response = response.json()['result'][0]['color1']

        # From new color, get details on the color(s)
        new_color = response['Name']
        self.db.user.set('color', new_color)
        buttons = [
            Button(text='Get Details',
                   flow="color_details",
                   data={'colorName': self.db.user.get('color')})
        ]
        image = Card(title=response['Name'],
                     image_url=response['imgURL'],
                     buttons=buttons,
                     mode="buttons",
                     passthru='true')

        #creating reply msg
        image_card = self.create_message(card=image)
        text = 'The best PPG paint that matches with your new ' + harmony \
        + ' color is ' + new_color + '. Here is what the color looks like:'
        reply_text = self.create_message(text=text)
        message = [reply_text, image_card]
        return self.respond(messages=message, action="check")
예제 #9
0
    def start(self):
        # instantiate the card
        image_url = "http://bit.ly/1NPO0xx"
        buttons = [
            Button(text='Cute', action="next"),
            Button(text='Not cute', action="next"),
            Button(text='Kind of cute', action="next")
        ]
        card = ImageWithButtons(image_url=image_url,
                                buttons=buttons,
                                mode="buttons")

        # create the message (note the `card` rather than `text`)
        message = self.create_message(card=card)

        # respond as you normally would
        return self.respond(message=message, action="next")
예제 #10
0
    def start(self):
        condition = str(self.db.flow.get('course_subject'))
        print condition
        conditional = self.db.table('course_data_1').filter(subject=condition)
        print conditional
        info = ""
        messages = []
        imgsrc = "https://s9.postimg.org/56ckls6gv/Duncan_Hall.jpg"
        for courses in conditional:
            title = "Course Title:" + str(courses.get('title'))
            location = "Location:" + str(courses.get('location'))
            find = location.find('DCH')
            if find > -1:
                imgsrc = self.db.table('img_data_1').filter(
                    location="DCH")[0].get('imgsrc')
            find = location.find('HUM')
            if find > -1:
                imgsrc = self.db.table('img_data_1').filter(
                    location="HUM")[0].get('imgsrc')
            find = location.find('HEB')
            if find > -1:
                imgsrc = self.db.table('img_data_1').filter(
                    location="HEB")[0].get('imgsrc')
            find = location.find('HRG')
            if find > -1:
                imgsrc = self.db.table('img_data_1').filter(
                    location="HRG")[0].get('imgsrc')
            description = "Discription:" + str(courses.get('description'))
            buttons = [
                Button(text="This course is great!", action="course_rock"),
                Button(text="This course is not so great!",
                       action="course_sucks"),
            ]
            card = Card(
                title=title,
                text=location + '\n' + '\n' + description,
                image_url=imgsrc,
                buttons=buttons,
            )
            message = self.create_message(card=card)
            messages.append(message)

        # self.db.table('course').filter(name__contains="COMP")
        return self.respond(messages=messages, action="next")
예제 #11
0
    def start(self):
        # importing from utilities
        api_host = host()

        # getting user color
        color = self.properties['colorName'].capitalize()
        url = '/colors?name='+color
        response = requests.get(api_host+url)
        response = response.json()['result']
        
        # getting color name and image
        if response['Color Name']:
            text = response['Color Name']
            self.db.user.set('color', text)
            
            # Color Details
            name =  str(self.db.user.get('color'))
            number = response['Color Number']
            r,g,b = str(response['R']),str(response['G']),str(response['B'])
            desc = response['Color Description']
            colName = response['Collection Name']
            imgURL = response['imgURL']
            ppg_url = more_info(name,number,colName)
            buttons = [Button(text="Go to PPG", url=ppg_url)]
            
            # Creating reply msg
            card = Card(
                     image_url=imgURL,
                     title=name,
                     buttons = buttons
            )
            text = 'The following is what I found in regards to ' + name +':'
            msg1 = self.create_message(text=text)
            msg2 = self.create_message(card=card)
            text = 'Description: ' + desc + '\n' + 'RGB: ( ' +r+', '+g+', '+b+ ' )' +'\n' + 'Color Number: ' + number
            msg3 = self.create_message(text=text)

            
            
            return self.respond(messages=[msg1,msg2,msg3], action="next")

        # color not found
        else:
            text = 'Unfortunately, I cannot find the color you are looking for.'
            message = self.create_message(text=text)
            return self.respond(message=message, action="next")
        return self.respond(message="error occured", action="next")
예제 #12
0
    def start(self):
        # importing from utilities
        api_host = host()
        colorDict = colors()

        #getting user color
        color = self.properties['colorName']

        #finding color from DB
        if color in colorDict:
            rgb = colorDict[color]
            r = str(rgb[0])
            g = str(rgb[1])
            b = str(rgb[2])
            url = '/colors?R=' + r + '&G=' + g + '&B=' + b
            response = requests.get(api_host + url)
            response = response.json()['result']

            #Getting color name and image
            text = response['Color Name']
            self.db.user.set('color', text)
            buttons = [
                Button(text='Get Details',
                       flow="color_details",
                       data={'colorName': self.db.user.get('color')})
            ]
            image = Card(title=text,
                         image_url=response['imgURL'],
                         buttons=buttons,
                         mode="buttons",
                         passthru='false')

            #creating reply msg
            image_card = self.create_message(card=image)
            text = 'The best PPG paint that matches with your color is ' + \
            text + '. Here is what the color looks like:'
            reply_text = self.create_message(text=text)
            message = [reply_text, image_card]
            return self.respond(messages=message, action="next")

        #color not found
        else:
            text = 'Unfortunately, I cannot find the color you are looking for.'
            message = self.create_message(text=text)
            return self.respond(message=message, action="next")
        return self.respond(message="error occured", action="next")
예제 #13
0
    def start(self):
        
        uid = self.db.user.id
        numItems = 0
        # Call middleware to retrieve card data
        try:
            response = requests.get("https://ec2.urkei.com/v1/giftbot/usercards?secret=cosmicsecret&userId="+uid)
            numItems = len(response.json())
        except:
            text = "Issue wihth card retreival."
            message = self.create_message(text=text)
            return self.respond(message=message, action="no_card")
        
        # construct a list of cards (they are `generic` template in Messenger)
        elements = []
        for x in range(numItems):
            cardName = response.json()[x]['name']
            cardKey = response.json()[x]['card_key']
            pin = response.json()[x]['pin']
            cardNumber = response.json()[x]['card_number']
            cardImage = response.json()[x]['image']
            print cardName
            # Single button
            buttons = [
                Button(text="Go to card", url=cardKey)
            ]
            element = Card(
                title=cardName,
                text=cardNumber+" / "+pin,
                item_url=cardKey,
                image_url=cardImage,
                buttons=buttons
            )
            elements.append(element)

        # `Cards` is a multi card element in Messenger
        card = Cards(elements=elements)

        # create the message (note the `card` rather than `text`)
        message = self.create_message(card=card)

        # respond as you normally would
        return self.respond(message=message, action="yes_card")
예제 #14
0
    def start(self):

        uid = self.db.flow.get('uuid')
        # Call middleware to retrieve card data
        try:
            response = requests.get(
                "http://ec2.urkei.com:9091/v1/giftbot/redeem?secret=cosmicsecret&uuid="
                + uid)
            print response
            cardName = response.json()['name']
            cardKey = response.json()['card_key']
            pin = response.json()['pin']
            cardNumber = response.json()['card_number']
            cardImage = response.json()['image']
            print cardName
        except:
            text = "Payment issue, try to redeem later."
            message = self.create_message(text=text)
            return self.respond(message=message, action="no_card")

        buttons = [Button(type="share")]
        # construct a list of cards (they are `generic` template in Messenger)
        elements = []
        element = Card(title=cardName,
                       text=cardNumber + " / " + pin,
                       item_url=cardKey,
                       image_url=cardImage,
                       buttons=buttons)
        elements.append(element)

        # `Cards` is a multi card element in Messenger
        card = Cards(elements=elements)

        # create the message (note the `card` rather than `text`)
        message = self.create_message(card=card)

        # respond as you normally would
        return self.respond(message=message, action="yes_card")
예제 #15
0
    def start(self):

        # Finding dominant color from uploaded image
        URL = str(self.db.flow.get('color_url'))
        data = {"url": URL}
        response = requests.post(url="https://ppgpaint-api.herokuapp.com",
                                 json=data)
        response = response.json()

        # Getting info on found dominant color
        closestColor = response['result']['colors'][0]['closestColor'][0]
        URL = '/colors?name=' + closestColor
        api_host = host()
        response = requests.get(api_host + URL)
        response = response.json()['result']

        #Getting color name and image
        text = response['Color Name']
        self.db.user.set('color', text)
        buttons = [
            Button(text='Get Details',
                   flow="color_details",
                   data={'colorName': self.db.user.get('color')})
        ]
        image = Card(title=text,
                     image_url=response['imgURL'],
                     buttons=buttons,
                     mode="buttons",
                     passthru='true')

        #creating reply msg
        image_card = self.create_message(card=image)
        text = 'The best PPG paint that matches with your color is ' + \
        text + '. Here is what the color looks like:'
        reply_text = self.create_message(text=text)
        message = [reply_text, image_card]
        return self.respond(messages=message, action="next")
예제 #16
0
파일: joke.py 프로젝트: sumaat143/community
    def start(self):
        """This demonstrates the use of a multi card reading data from
        an external datasource and then using various button types to
        transition to different states, flows, websites"""

        titles = ["Norris Joke #1", "Norris Joke #2"]
        jokes = [self.get_joke(), self.get_joke()]
        images = [
            "http://i.imgur.com/3jLvQ78.jpg", "http://i.imgur.com/6JADDnQ.jpg"
        ]
        # I'll test the three buttons types: link, transition, start
        # What's nice is that any of this data can be obtained programmatically
        # or via API
        buttons = [[
            Button(text="Learn", url="https://en.wikipedia.org"),
            Button(text="Next", action="next1"),
            Button(text="GO!", flow="cardbot_bonus", data={'foo': "bar1"})
        ],
                   [
                       Button(text="Fun", url="https://www.reddit.com"),
                       Button(text="Next", action="next2", data={'ok': True}),
                       Button(text="GO!",
                              flow="cardbot_bonus",
                              data={'foo': "bar2"})
                   ]]
        # construct a list of cards (they are `generic` template in Messenger)
        elements = []
        for x in range(2):
            element = Card(title=titles[x],
                           text=jokes[x],
                           image_url=images[x],
                           buttons=buttons[x])
            elements.append(element)

        # `Cards` is a multi card element in Messenger
        card = Cards(elements=elements)

        # create the message (note the `card` rather than `text`)
        message = self.create_message(card=card)

        # respond as you normally would
        return self.respond(message=message)
예제 #17
0
    def start(self):
        # instantiate the card
        buttons = [
            Button(text='See Wikipedia page',
                   url='https://en.wikipedia.org/wiki/African_elephant'),
            Button(text='See more', action='next'),
            Button(text='Vote', flow='vote_result', data={'vote': 'african'})
        ]
        element1 = Card(
            title='African Elephant',
            text=
            'One species of African elephant is the largest living terrestrial animal.',
            item_url='https://en.wikipedia.org/wiki/African_elephant',
            image_url='http://i.imgur.com/7Z9IX5W.jpg',
            buttons=buttons)

        buttons = [
            Button(text='See Wikipedia page',
                   url='https://en.wikipedia.org/wiki/Asian_elephant'),
            Button(text='See more', action='next'),
            Button(text='Vote', flow='vote_result', data={'vote': 'asian'})
        ]
        element2 = Card(
            title='African Elephant',
            text=
            'In general, the Asian elephant is smaller than the African elephant.',
            item_url='https://en.wikipedia.org/wiki/Asian_elephant',
            image_url='http://i.imgur.com/w5qzZ7I.jpg',
            buttons=buttons)

        card = Cards(elements=[element1, element2])

        # create the message (note the `card` rather than `text`)
        message = self.create_message(card=card)

        # respond as you normally would
        return self.respond(message=message, action="next")
예제 #18
0
    def start(self):

        ## Full feature list
        full_ft_list = ['Sound', 'Touch', 'Smell', 'Sight']

        ## Get current feature list from the flow scope
        ft_list = self.db.flow.get('sclass_ft_list')

        ## If there is no feature list in the flow scope set it as the full list
        if (ft_list == 'starting'):
            ft_list = full_ft_list

        ## Get current feature
        current_ft = self.db.flow.get('sclass_ft')
        print current_ft

        ## Get message for the current feature (var current_ft_message = message)
        current_ft_message, entity = self.cms.get(
            "s_class_leaflet", "msg_ft_" + current_ft.lower())
        msg_next_sense, entity = self.cms.get("s_class_leaflet",
                                              "msg_next_sense")
        msg_next_step, entity = self.cms.get("s_class_leaflet",
                                             "msg_next_step")

        ## Remove current feature from the list of flow scope
        ft_list.remove(current_ft)

        ## Set new features list to the flow scope
        self.db.flow.set('sclass_ft_list', ft_list)

        ## Set buttons
        buttons = []
        for item in ft_list:
            element = Button(text=item,
                             action='self',
                             data=({
                                 'sclass_ft': item
                             }))
            buttons.append(element)

        ## Add "next step" button if there is less than 2 buttons
        if (len(buttons) < 3):
            next_step_message, entity = self.cms.get("s_class_leaflet",
                                                     "msg_take_to_next_step")
            buttons.append(
                Button(text=next_step_message, flow='s_class_leaflet_04'))

        print len(buttons)

        ## Complete he current message with the right sentence
        if (len(buttons) == 1):
            ft_complete_message = current_ft_message + msg_next_step
        else:
            ft_complete_message = current_ft_message + msg_next_sense

        ## Create Card component
        card = TextWithButtons(text=ft_complete_message, buttons=buttons)

        ## Create message itself
        message = self.create_message(card=card)

        ## Return the respond object
        return self.respond(message=message, action="next")
예제 #19
0
    def start(self):

        # getting selected color details
        color = str(self.db.user.get('color'))
        api_host = host()
        URL = '/colors?name=' + color
        response = requests.get(api_host + URL)
        response = response.json()['result']

        # initializing urls of the shade colors of selected color
        elements = []

        num_url = api_host + '/colors?color-number='

        # accent1_URL =  requests.get(num_url + response['Accent 1'])
        # accent2_URL =  requests.get(num_url + response['Accent 2'])
        # trim1_URL =  requests.get(num_url + response['Trim 1'])
        # trim2_URL =  requests.get(num_url + response['Trim 2'])
        shade1_URL = requests.get(num_url + response['Shade 1'])
        shade2_URL = requests.get(num_url + response['Shade 2'])
        shade3_URL = requests.get(num_url + response['Shade 3'])
        shade4_URL = requests.get(num_url + response['Shade 4'])
        shade5_URL = requests.get(num_url + response['Shade 5'])
        shade6_URL = requests.get(num_url + response['Shade 6'])

        # SHADE 1
        response = shade1_URL.json()['result']
        buttons = [
            Button(text="Get Details",
                   flow="color_details",
                   data={'colorName': response['Color Name']}),
            Button(text="Go to PPG",
                   url=more_info(response['Color Name'],
                                 response['Color Number'],
                                 response['Collection Name']))
        ]

        element = Card(title=response['Color Name'],
                       text='Shade 1',
                       image_url=response['imgURL'],
                       buttons=buttons)

        elements.append(element)

        # SHADE 2
        response = shade2_URL.json()['result']

        buttons = [
            Button(text="Get Details",
                   flow="color_details",
                   data={'colorName': response['Color Name']}),
            Button(text="Go to PPG",
                   url=more_info(response['Color Name'],
                                 response['Color Number'],
                                 response['Collection Name']))
        ]

        element = Card(title=response['Color Name'],
                       text='Shade 2',
                       image_url=response['imgURL'],
                       buttons=buttons)

        elements.append(element)

        # SHADE 3
        response = shade3_URL.json()['result']

        buttons = [
            Button(text="Get Details",
                   flow="color_details",
                   data={'colorName': response['Color Name']}),
            Button(text="Go to PPG",
                   url=more_info(response['Color Name'],
                                 response['Color Number'],
                                 response['Collection Name']))
        ]

        element = Card(title=response['Color Name'],
                       text='Shade 3',
                       image_url=response['imgURL'],
                       buttons=buttons)

        elements.append(element)

        # SHADE 4
        response = shade4_URL.json()['result']

        buttons = [
            Button(text="Get Details",
                   flow="color_details",
                   data={'colorName': response['Color Name']}),
            Button(text="Go to PPG",
                   url=more_info(response['Color Name'],
                                 response['Color Number'],
                                 response['Collection Name']))
        ]

        element = Card(title=response['Color Name'],
                       text='Shade 4',
                       image_url=response['imgURL'],
                       buttons=buttons)

        elements.append(element)

        # SHADE 5
        response = shade5_URL.json()['result']
        buttons = [
            Button(text="Get Details",
                   flow="color_details",
                   data={'colorName': response['Color Name']}),
            Button(text="Go to PPG",
                   url=more_info(response['Color Name'],
                                 response['Color Number'],
                                 response['Collection Name']))
        ]

        element = Card(title=response['Color Name'],
                       text='Shade 5',
                       image_url=response['imgURL'],
                       buttons=buttons)
        elements.append(element)

        # SHADE 6
        response = shade6_URL.json()['result']

        buttons = [
            Button(text="Get Details",
                   flow="color_details",
                   data={'colorName': response['Color Name']}),
            Button(text="Go to PPG",
                   url=more_info(response['Color Name'],
                                 response['Color Number'],
                                 response['Collection Name']))
        ]

        # creating reply msg
        element = Card(title=response['Color Name'],
                       text='Shade 6',
                       image_url=response['imgURL'],
                       buttons=buttons)

        elements.append(element)

        card = Cards(elements=elements)
        message = self.create_message(card=card)

        return self.respond(message=message)
예제 #20
0
    def start(self):

        type_description = self.db.flow.get('team') or ""
        type_description = type_description.lower().strip()
        cardsToDisplay = [[]]
        if 'featured' == type_description:
            cardsToDisplay = [["gyft-4698", "gyft-4614"],
                              ["gyft-3558", "gyft-3559", "gyft-4061"],
                              ["gyft-4068", "gyft-4069", "gyft-2974"]]
        if 'restaurants' == type_description:
            cardsToDisplay = [["gyft-4698", "gyft-4614"],
                              ["gyft-3558", "gyft-3559", "gyft-4061"],
                              ["gyft-4068", "gyft-4069", "gyft-2974"]]
        if 'retail stores' == type_description:
            cardsToDisplay = [["gyft-4698", "gyft-4614"],
                              ["gyft-3558", "gyft-3559", "gyft-4061"],
                              ["gyft-4068", "gyft-4069", "gyft-2974"]]
        if 'entertainment' == type_description:
            cardsToDisplay = [["gyft-4698", "gyft-4614"],
                              ["gyft-3558", "gyft-3559", "gyft-4061"],
                              ["gyft-4068", "gyft-4069", "gyft-2974"]]
        if 'home goods' == type_description:
            cardsToDisplay = [["gyft-4698", "gyft-4614"],
                              ["gyft-3558", "gyft-3559", "gyft-4061"],
                              ["gyft-4068", "gyft-4069", "gyft-2974"]]
        if 'students' == type_description:
            cardsToDisplay = [["gyft-4698", "gyft-4614"],
                              ["gyft-3558", "gyft-3559", "gyft-4061"],
                              ["gyft-4068", "gyft-4069", "gyft-2974"]]
        if len(cardsToDisplay) == 0:
            return self.respond(message=None, action="no_card")

        # construct a list of cards (they are `generic` template in Messenger)
        elements = []
        nCards = len(cardsToDisplay)
        for cardIdx in range(nCards):
            nValues = len(cardsToDisplay[cardIdx])
            cardName = ""
            cardImage = ""
            buttons = []
            for valueIdx in range(nValues):
                response = requests.get(
                    "http://ec2.urkei.com:9091/v1/giftbot/carddetail?cardId=" +
                    cardsToDisplay[cardIdx][valueIdx])
                cardName = response.json()['merchantName']
                cardImage = response.json()['merchantCardImageUrl']
                cardValue = response.json()['priceAsString']
                cardCurr = response.json()['currencyCode']
                # Buttons for values
                buttons.append(
                    Button(text=cardCurr + " " + cardValue,
                           action="next",
                           data={'cardId': cardsToDisplay[cardIdx][valueIdx]}))

            element = Card(title=cardName,
                           text="Gyft card",
                           image_url=cardImage,
                           buttons=buttons)
            elements.append(element)

        # `Cards` is a multi card element in Messenger
        card = Cards(elements=elements)

        # create the message (note the `card` rather than `text`)
        message = self.create_message(card=card)

        # respond as you normally would
        return self.respond(message=message)
예제 #21
0
파일: Budget.py 프로젝트: as409/Amber.ai
    def start(self):
        
        checkin = self.db.flow.get("checkin-date") 
        checkout = self.db.flow.get("checkout-date") 
        city = self.db.flow.get("CITY1")
        price1=self.db.flow.get("price1")
        price2=self.db.flow.get("price2")



        url = "PASTE THE URLs OF YOUR TRAVEL APIs"
        payload = "{\n \"destination_code\": \""+city+"\",\n \"checkin\": \""+checkin+"\",\n \"checkout\": \""+checkout+"\",\n \"client_nationality\": \"IN\",\n \"response\": \"fast\",\n \"currency\": \"INR\",\n \"rates\": \"comprehensive\",\n \"hotel_category\": [2, 6],\n \"rooms\": [\n {\n \"adults\": 1\n },\n {\n \"adults\": 2,\n \"children_ages\": [3]\n }\n ]\n}"
        headers = {
            'api-key': "PASTE YOUR KEY HERE",
            'content-type': "application/json",
            'accept': "application/json",
            'cache-control': "no-cache",
            'postman-token': "2c0f1442-19fc-2cc3-8bfd-efcb806d23a7"
            }
        response = requests.request("POST", url, data=payload, headers=headers)


        price_list=[]
        number=[]
        for i in range(70):
            price=response.json()['hotels'][i]['rates'][0]['price']
            price=price + 0.05*(price)
            price_list.append(price)
            
        number=[]
        i=0
        for price in price_list:
            if ((price) < int(price2)):
                number.append(i)
                i=i+1
            
        
        url1= response.json()['hotels'][number[0]]['images']['main_image']
        image_url1= 'Paste home url here' + url1
        title1 = response.json()['hotels'][number[0]]['name']
        text1 =  response.json()['hotels'][number[0]]['rates'][0]['price']
        text1=str(text1)
        text1='INR' + text1
        
        
        url2= response.json()['hotels'][number[1]]['images']['main_image']
        image_url2= 'Paste home url here' + url2
        title2 =response.json()['hotels'][number[1]]['name']
        text2 =  response.json()['hotels'][number[1]]['rates'][0]['price']
        text2=str(text2)
        text2='INR ' + text2
        
        url3= response.json()['hotels'][number[2]]['images']['main_image']
        image_url3= 'Paste home url here' + url3
        title3 =response.json()['hotels'][number[2]]['name']
        text3 =  response.json()['hotels'][number[2]]['rates'][0]['price']
        text3=str(text3)
        text3='INR ' + text3
        
        
        
        url4= response.json()['hotels'][number[3]]['images']['main_image']
        image_url4= 'Paste home url here' + url4
        title4 =response.json()['hotels'][number[3]]['name']
        text4 =  response.json()['hotels'][number[3]]['rates'][0]['price']
        text4=str(text4)
        text4='INR ' + text4
        
        buttons = [
            Button(text='View details'),
            ]
            
        
        buttons_last = [
            Button(text='View details'),
            Button(text='Load more')
            ]
            
        card1 = Card(title=title1,
        text=text1,
        image_url=image_url1,
        buttons=buttons)
        message1 = self.create_message(card=card1)
        
        card2 = Card(title=title2,
        text=text2,
        image_url=image_url2,
        buttons=buttons)
        message2 = self.create_message(card=card2)
        
        
        card3 = Card(title=title3,
        text=text3,
        image_url=image_url3,
        buttons=buttons)
        message3 = self.create_message(card=card3)
        
        
        card4 = Card(title=title4,
        text=text4,
        image_url=image_url4,
        buttons=buttons_last)
        message4 = self.create_message(card=card4)
        
        

        # respond with the message and "next" action
        return self.respond(message=[message1,message2,message3,message4], action="next")