json api chatfuel的python包装器
python-chatfuel-class的Python项目详细描述
python chatfuel类
描述:json api chatfuel的python包装器
这个项目的灵感来自php-chatfuel-class
功能列表:
- 发送文本:
defsendText(self,messages=None)
- 发送图像
defsendImage(self,url_image)
- 发送音频
defsendAudio(self,url):
- 发送视频
defsendVideo(self,url)
- 发送文本卡
defsendTextCard(self,text,buttons)
- 发送库
defsendGallery(self,elements)
- 发送列表
defsendList(self,elements)
- 发送快速回复
defsendQuickReply(self,text,quickReplies)
- 创建元素
defcreateElement(self,title,image,subTitle,buttons)
- 创建要阻止的按钮
defcreateButtonToBlock(self,title,block,setAttributes=None)
- 创建URL按钮
defcreateButtonToURL(self,title,url)
- 创建回发按钮
defcreatePostBackButton(self,title,url_plugin)
- 创建呼叫按钮
defcreateCallButton(self,title,phoneNumber)
- 创建共享按钮
def_createShareButton(self)
- 创建附件
defcreateAttachment(self,_type,payload)
你可以在这里看到代码class_chatfuel.py
安装
对于python 2x
pip install python_chatfuel_class
对于python 3x
pip3 install python_chatfuel_class
用法
- 发送文本:
@app.route('/sendText/<text>')defsendText(text):chatfuel=Chatfuel()chatfuel.sendText(text)returnchatfuel.get_response()
- 发送图像:
@app.route('/sendImage/')defsendImage():chatfuel=Chatfuel()url_image=''chatfuel.sendImage(url_image)returnchatfuel.get_response()
- 发送音频:
@app.route('/sendAudio/')defsendAudio():chatfuel=Chatfuel()url_audio=''chatfuel.sendAudio(url_audio)returnchatfuel.get_response()
- 发送视频:
@app.route('/sendVideo/')defsendVideo():chatfuel=Chatfuel()url_video=''chatfuel.sendVideo(url_video)returnchatfuel.get_response()
- 发送按钮到块:
@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()
- 发送按钮到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()
- 发回按钮:
@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()
- 发送按钮呼叫:
@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()
- 发送库:
@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()
- 发送列表:
@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()
- 发送快速回复:
@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()
- 重定向块
@app.route('/redirectBlock/')defredirectBlock():returnjson.dumps({"redirect_to_blocks":["Welcome message","Default answer"]})