Skip to content

Repository files navigation

Python Chatfuel Class

GitHub licenseTravisPyPIPyPI - Python VersionGitHub stars

Descrpition: Python Wrapper for JSON API Chatfuel

This project was inspired by php-chatfuel-class

Functions List:

  • Send Text:
defsendText(self, messages=None)
  • Send Image
defsendImage(self, url_image)
  • Send Audio
defsendAudio(self, url):
  • Send Video
defsendVideo(self, url)
  • Send Text Card
defsendTextCard(self, text, buttons)
  • Send Gallery
defsendGallery(self, elements)
  • Send List
defsendList(self, elements)
  • Send Quick Reply
defsendQuickReply(self, text, quickReplies)
  • Create Element
defcreateElement(self, title, image, subTitle, buttons)
  • Create Button To Block
defcreateButtonToBlock(self, title, block, setAttributes=None)
  • Create Button To URL
defcreateButtonToURL(self, title, url)
  • Create PostBack Button
defcreatePostBackButton(self, title, url_plugin)
  • Create Call Button
defcreateCallButton(self, title, phoneNumber)
  • Create Share Button
def_createShareButton(self)
  • Create Attachment
defcreateAttachment(self, _type, payload)

You can see the code at here class_chatfuel.py

Installation

For python 2x
pip install python_chatfuel_class
For python 3x
pip3 install python_chatfuel_class

Usage

  • Send Text:
@app.route('/sendText/<text>')defsendText(text):
chatfuel=Chatfuel()
chatfuel.sendText(text)
returnchatfuel.get_response()

send-text

  • Send Image:
@app.route('/sendImage/')defsendImage():
chatfuel=Chatfuel()
url_image=''chatfuel.sendImage(url_image)
returnchatfuel.get_response()

send-Image

  • Send Audio:
@app.route('/sendAudio/')defsendAudio():
chatfuel=Chatfuel()
url_audio=''chatfuel.sendAudio(url_audio)
returnchatfuel.get_response()

send-Audio

  • Send Video:
@app.route('/sendVideo/')defsendVideo():
chatfuel=Chatfuel()
url_video=''chatfuel.sendVideo(url_video)
returnchatfuel.get_response()

send-Video

  • Send Button to Block:
@app.route('/sendTextCard/ButtonToBlock')defcreateButtonToBlock():
chatfuel=Chatfuel()
ButtonToBlock=chatfuel.createButtonToBlock(
'Button To Block',
['#block_1', '#block_2'],
{'setAttribute_1': 'value_1'}
)
chatfuel.sendTextCard('Clicking the button below!', [ButtonToBlock])
returnchatfuel.get_response()

Button to Block

  • Send Button to URL:
@app.route('/sendTextCard/ButtonToURL')defButtonToURL():
chatfuel=Chatfuel()
ButtonToURL=chatfuel.createButtonToURL(
'Button To URL',
'url_website',
)
chatfuel.sendTextCard('Clicking the button below!', [ButtonToURL])
returnchatfuel.get_response()

Button To URL

  • Send Button Post Back:
@app.route('/sendTextCard/PostBackButton')defPostBackButton():
chatfuel=Chatfuel()
PostBackButton=chatfuel.createPostBackButton(
'Post Back Button',
'url_plugin',
)
chatfuel.sendTextCard('Clicking the button below!', [PostBackButton])
returnchatfuel.get_response()

PostBack Button

  • Send Button Call:
@app.route('/sendTextCard/CallButton')defCallButton():
chatfuel=Chatfuel()
CallButton=chatfuel.createCallButton(
'Call Button',
'Phone_number', #example; +84919666666
)
chatfuel.sendTextCard('Clicking the button below!', [CallButton])
returnchatfuel.get_response()

Call Button

  • Send Gallery:
@app.route('/sendGallery/')defsendGallery():
chatfuel=Chatfuel()
elements= []
#maximum 3 buttonbutton_access_url=chatfuel.createButtonToURL('Access Website', 'https://www.google.com.vn')
button_call=chatfuel.createCallButton('+84919666666')
button_share=chatfuel.createShareButton()
title='Send Gallery'image_url=''subTitle='subTitle Item'foriinrange(5):
elements.append(chatfuel.createElement(title, image_url, subTitle, [button_access_url, button_call, button_share]))
chatfuel.sendGallery(elements)
returnchatfuel.get_response()

send-Gallery

  • Send List:
@app.route('/sendList/')defsendList():
#minimum 2 items in one List (Elements)#maximum 4 items in one List (Elements)chatfuel=Chatfuel()
elements= []
button_access_url=chatfuel.createButtonToURL('Access Website', 'https://www.google.com.vn')
title='Send List'image_url=''subTitle='subTitle Item'foriinrange(2):
elements.append(chatfuel.createElement(title, image_url, subTitle, [button_access_url]))
chatfuel.sendList(elements)
returnchatfuel.get_response()

send-List

  • Send Quick Reply:
@app.route('/sendQuickReply/')defsendQuickReply():
chatfuel=Chatfuel()
button_quick_replies_attributes=chatfuel.createButtonToBlock(
'Send Quick Reply',
['#block_1'],
{'setAttributes_1': 'value_1'},
)
button_quick_replies=chatfuel.createButtonToBlock('Title', ['#block_1'])
chatfuel.sendQuickReply('Text', [button_quick_replies_attributes, button_quick_replies])
returnchatfuel.get_response()

send-Quick-Reply

  • Redirect Block
@app.route('/redirectBlock/')defredirectBlock():
returnjson.dumps({"redirect_to_blocks": ["Welcome message", "Default answer"]})

Redirect Block

Demo:

Author: @Peter Dinh

About

This project was inspired by php-chatfuel-class

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages