Skip to content

Commit 8fff5a2

Browse files
author
Pashutan Modaresi
committed
Add functions to send rich media
1 parent a5e1453 commit 8fff5a2

15 files changed

Lines changed: 308 additions & 313 deletions

File tree

docs/autogen.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,18 @@
2626
fbotics.models.payloads.generic_template.GenericDefaultAction,
2727
],
2828
},
29-
{"page": "client/client.md", "methods": [Client.send_button_template]},
29+
{
30+
"page": "client/client.md",
31+
"methods": [
32+
Client.send_button_template,
33+
Client.send_text,
34+
Client.send_audio,
35+
Client.send_image,
36+
Client.send_file,
37+
Client.send_generic_template,
38+
Client.send_quick_replies,
39+
],
40+
},
3041
{
3142
"page": "quick_replies/quick_replies.md",
3243
"classes": [fbotics.models.quick_reply.QuickReply],
@@ -51,7 +62,7 @@ def get_class_attr(Cls) -> []:
5162
a
5263
for a, v in Cls.__dict__.items()
5364
if not re.match("<function.*?>", str(v))
54-
and not (a.startswith("__") and a.endswith("__"))
65+
and not (a.startswith("__") and a.endswith("__"))
5566
]
5667

5768

@@ -76,7 +87,7 @@ def get_function_signature(function, method=True):
7687
else:
7788
args = signature.args
7889
if defaults:
79-
kwargs = zip(args[-len(defaults):], defaults)
90+
kwargs = zip(args[-len(defaults) :], defaults)
8091
args = args[: -len(defaults)]
8192
else:
8293
kwargs = []
@@ -139,8 +150,8 @@ def count_leading_spaces(s):
139150
def process_list_block(docstring, starting_point, section_end, leading_spaces, marker):
140151
ending_point = docstring.find("\n\n", starting_point)
141152
block = docstring[
142-
starting_point: (None if ending_point == -1 else ending_point - 1)
143-
]
153+
starting_point : (None if ending_point == -1 else ending_point - 1)
154+
]
144155
# Place marker for later reinjection.
145156
docstring_slice = docstring[starting_point:section_end].replace(block, marker)
146157
docstring = docstring[:starting_point] + docstring_slice + docstring[section_end:]
@@ -184,7 +195,7 @@ def process_docstring(docstring):
184195
if "```" in docstring:
185196
tmp = docstring[:]
186197
while "```" in tmp:
187-
tmp = tmp[tmp.find("```"):]
198+
tmp = tmp[tmp.find("```") :]
188199
index = tmp[3:].find("```") + 6
189200
snippet = tmp[:index]
190201
# Place marker in docstring for later reinjection.
@@ -209,9 +220,9 @@ def process_docstring(docstring):
209220
leading_spaces = spaces
210221
if leading_spaces:
211222
snippet_lines = (
212-
[snippet_lines[0]]
213-
+ [line[leading_spaces:] for line in snippet_lines[1:-1]]
214-
+ [snippet_lines[-1]]
223+
[snippet_lines[0]]
224+
+ [line[leading_spaces:] for line in snippet_lines[1:-1]]
225+
+ [snippet_lines[-1]]
215226
)
216227
snippet = "\n".join(snippet_lines)
217228
code_blocks.append(snippet)
@@ -351,10 +362,10 @@ def read_page_data(page_data, type):
351362
continue
352363
module_member = getattr(module, name)
353364
if (
354-
inspect.isclass(module_member)
355-
and type == "classes"
356-
or inspect.isfunction(module_member)
357-
and type == "functions"
365+
inspect.isclass(module_member)
366+
and type == "classes"
367+
or inspect.isfunction(module_member)
368+
and type == "functions"
358369
):
359370
instance = module_member
360371
if module.__name__ in instance.__module__:
@@ -368,7 +379,7 @@ def read_page_data(page_data, type):
368379
if __name__ == "__main__":
369380
readme = read_file("../README.md")
370381
index = read_file("templates/index.md")
371-
index = index.replace("{{autogenerated}}", readme[readme.find("##"):])
382+
index = index.replace("{{autogenerated}}", readme[readme.find("##") :])
372383
with open("sources/index.md", "w") as f:
373384
f.write(index)
374385

@@ -428,7 +439,7 @@ def read_page_data(page_data, type):
428439
if os.path.exists(path):
429440
template = read_file(path)
430441
assert "{{autogenerated}}" in template, (
431-
"Template found for " + path + " but missing {{autogenerated}}" " tag."
442+
"Template found for " + path + " but missing {{autogenerated}}" " tag."
432443
)
433444
mkdown = template.replace("{{autogenerated}}", mkdown)
434445
print("...inserting autogenerated content into template:", path)

docs/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ nav:
1313
- Home: index.md
1414
- Client: client/client.md
1515
- Text Message: text/example.md
16+
- Rich Media: rich_media/example.md
1617
- Quick Replies:
1718
- Quick Reply: quick_replies/quick_replies.md
1819
- Example: quick_replies/example.md
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
This is an example to send rich media using FBotics:
2+
3+
```python
4+
from fbotics.client import Client
5+
from fbotics.models.quick_reply import QuickReply
6+
7+
client = Client(page_access_token=PAGE_ACCESS_TOKEN)
8+
9+
10+
qr1 = QuickReply(
11+
dict(
12+
content_type="text",
13+
title="Yes",
14+
payload="payload1",
15+
image_url="http://i64.tinypic.com/1hothh.png",
16+
)
17+
)
18+
qr2 = QuickReply(
19+
dict(
20+
content_type="text",
21+
title="No",
22+
payload="payload2",
23+
image_url="http://i63.tinypic.com/2pqpbth.png",
24+
)
25+
)
26+
27+
response = client.send_image(
28+
recipient_id=RECIPIENT_ID, url="http://i63.tinypic.com/2zfprph.png", quick_replies=[qr1, qr2]
29+
)
30+
31+
response = client.send_audio(
32+
recipient_id=recipient_id, url="http://www.pacdv.com/sounds/voices/mmm-1.wav", quick_replies=[qr1, qr2]
33+
)
34+
35+
response = client.send_file(
36+
recipient_id=recipient_id, url="http://www.xmlpdf.com/manualfiles/hello-world.pdf", quick_replies=[qr1, qr2]
37+
)
38+
39+
```

fbotics/_version.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
120120
dirname = os.path.basename(root)
121121
if dirname.startswith(parentdir_prefix):
122122
return {
123-
"version": dirname[len(parentdir_prefix):],
123+
"version": dirname[len(parentdir_prefix) :],
124124
"full-revisionid": None,
125125
"dirty": False,
126126
"error": None,
@@ -132,8 +132,8 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
132132

133133
if verbose:
134134
print(
135-
"Tried directories %s but none started with prefix %s"
136-
% (str(rootdirs), parentdir_prefix)
135+
"Tried directories %s but none started with prefix %s"
136+
% (str(rootdirs), parentdir_prefix)
137137
)
138138
raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
139139

@@ -190,7 +190,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
190190
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
191191
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
192192
TAG = "tag: "
193-
tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)])
193+
tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)])
194194
if not tags:
195195
# Either we're using git < 1.8.3, or there really are no tags. We use
196196
# a heuristic: assume all version tags have a digit. The old git %d
@@ -207,7 +207,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
207207
for ref in sorted(tags):
208208
# sorting will prefer e.g. "2.0" over "2.0rc1"
209209
if ref.startswith(tag_prefix):
210-
r = ref[len(tag_prefix):]
210+
r = ref[len(tag_prefix) :]
211211
if verbose:
212212
print("picking %s" % r)
213213
return {
@@ -307,7 +307,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
307307
tag_prefix,
308308
)
309309
return pieces
310-
pieces["closest-tag"] = full_tag[len(tag_prefix):]
310+
pieces["closest-tag"] = full_tag[len(tag_prefix) :]
311311

312312
# distance: number of commits since tag
313313
pieces["distance"] = int(mo.group(2))

0 commit comments

Comments
 (0)