I am developing a little app where I would like to include a button that will open outlook email editor and presented the user with an empty content but a particular subject ready to be filled in by the user and sent back to a particular email.
Does anyone know how to do that?
What I was reading in different solutions does not work:
this for instance opens a url that fails
import ipyvuetify as v
v_btn = v.Btn(class_ = 'mx-2 light-blue darken-1',
href = 'href="mailto:vinoth#email.com?subject=title&body=The message"',
children = ['send email?'])
v_btn
Other option might be to create a ipyvuetify template:
class sendemail(v.VuetifyTemplate):
subject = Unicode('').tag(sync=True)
label = Unicode('email').tag(sync=True)
template = Unicode('''<v-btn
color="primary"
class="ma-1"
#click="sendemail(subject)"
>
{{ theemail }}
</v-btn>
<script>
export default {
methods: {
sendemail (subject) {
var email = "whatever#company.org";
document.location = "mailto:" + email +"?subject=" + subject + "&body=the body";
},
},
}
</script>''').tag(sync=True)
emailitBtn = clipboardBtn(subject='This is the subject of the email', label='send email')
emailitBtn
But this solution does not work neither.
any ideas?
maybe try
import ipyvuetify as v
v_btn = v.Btn(class_ = 'mx-2 light-blue darken-1',
href = 'mailto:vinoth#email.com?subject=title&body=The message',
target = '_blank',
children = ['send email?'])
v_btn
I removed the 'href' in the href property and added target='_blank' to open it in a new Window and it seems to work.
Related
I am creating a Facebook messenger chatbot with pymessenger, flask and wit.at. I want to add buttons as options in my chatbot conversation.
For example
"🎀 Generic Offer 1"+"\n"+"🎀 Generic Offer 2"+"\n"+"🎀 Generic Offer 3"
is what I want to show up as a button to user instead of just text. So the user can select one offer. Facebook has the option to add buttons https://developers.facebook.com/docs/messenger-platform/send-messages/template/button/ via JSON.
I want to do the similar thing. But I don't know how to do it. I can do simple text thing but now this, because I don't know JSON. As of now, my chatbot is replying via bot.send_text_message(sender_id, response).
def webhook():
data = request.get_json()
log(data)
if data['object'] == 'page':
for entry in data['entry']:
for messaging_event in entry['messaging']:
sender_id = messaging_event['sender']['id']
recipient_id = messaging_event['recipient']['id']
if messaging_event.get('message'):
if 'text' in messaging_event['message']:
messaging_text = messaging_event['message']['text']
else:
messaging_text = 'no text'
response = None
entity, value = wit_response(messaging_text)
if entity == 'newstype':
response = "OK. I will send you {} news".format(str(value))
elif entity == 'cust_greet':
response = get_message()
elif entity == 'cust_greet2':
response = get_message2()
elif entity == 'cust_offer':
#response = offer_response
response = "🎀 Generic Offer 1"+"\n"+"🎀 Generic Offer 2"+"\n"+"🎀 Generic Offer 3"+"\n"+" 🏷️ for more offer enter your cust id"
#val_off = test.val_off
bot.send_text_message(sender_id, response)
I think instead of bot.send_text_message, the correct way to send the JSON payload is via bot.send_raw. So using the example from your link you can test if it's working with something similar to:
payload = """{
"recipient":{
"id":"<PSID>"
},
"message":{
"attachment":{
"type":"template",
"payload":{
"template_type":"button",
"text":"What do you want to do next?",
"buttons":[
{
"type":"web_url",
"url":"https://www.example1.com",
"title":"Visit Example 1"
},
{
"type":"web_url",
"url":"https://www.example2.com",
"title":"Visit Example 2"
}
]
}
}
}
}"""
bot.send_raw(payload)
Don't forget to replace <PSID>.
I am developing an angularjs app on google app engine however I have an issue displaying one of my KeyProperty fields client.
This is how the KeyProperty field is displaying (The other non KeyProperty elements are showing up fine);
NB: Post is 200 OK
model.py
class Project(ndb.Model):
projectID = ndb.IntegerProperty(required=True)
title = ndb.StringProperty(required=True)
description = ndb.StringProperty(required=True)
startAt = ndb.DateTimeProperty(indexed=True)
endAt = ndb.DateTimeProperty()
client = ndb.KeyProperty(kind='Client')
class Client(ndb.Model):
name = ndb.StringProperty()
home.html element
<div class="form-group">
<label>Client : </label>
<input type="text" ng-model="Project.Client" class="form-control"/>
</div>
In handler.py
def post(self):
r = json.loads(self.request.body)
print str(r)
cl = Client(name=r['Client']).put()
client_key = cl
g = Project(projectID=int(r['ProjectID']),
client=client_key,
description=r['Description'],
title=r['Title'],
startAt=datetime.strptime(r['StartAt'], '%Y-%m-%dT%H:%M:%S.%fZ'),
endAt=datetime.strptime(r['EndAt'], '%Y-%m-%dT%H:%M:%S.%fZ'))
project_key = g.put()
angular
eventClick: function (project) {
$scope.showSelected = true;
var fromDate = moment(project.start).format('DD/MM/YYYY LT');
var endDate = moment(project.end).format('DD/MM/YYYY LT');
$scope.Project = {
ProjectID : project.projectID,
Client : project.client,
Title : project.title,
Description: project.description,
Employees: project.employees,
StartAt : fromDate,
EndAt : endDate,
IsFullDay : false
}
$scope.ShowModal()
},
I am still learning my way to handling KeyProperties. Thanks for the help
UPDATE
This is the error I am getting when I type 'qwert' in the Client field;
I am talking about in your Python code. The error log should tell you what line of your code was expecting a string. That is where you need the .name
I'm using facebook-python-ads-sdk,and i have gone through the pertinent document:
https://developers.facebook.com/docs/marketing-api/guides/carousel-ads#spec
But i didn't find the multi_share_end_card class attribute.
class LinkData(ValidatesFields, AbstractObject):
class Field(object):
call_to_action = 'call_to_action'
caption = 'caption'
child_attachments = 'child_attachments'
description = 'description'
image_hash = 'image_hash'
image_crops = 'image_crops'
link = 'link'
message = 'message'
multi_share_optimized = 'multi_share_optimized'
name = 'name'
picture = 'picture'
Is this a bug?Thanks for any answer.
Maybe it's a bug. ;-)
I solved the problem from facebook-python-ads-sdk/issues/129.
At first,i tried:
link = LinkData()
link[LinkData.Field.link] = link
link[LinkData.Field.call_to_action] = call_to_action
link[LinkData.Field.child_attachments] = child_attachments
link[LinkData.Field.message] = message
# remove the multi_share_end_card
link['multi_share_end_card'] = False
I got the following error:
FacebookBadObjectError: "multi_share_end_card" is not a valid field of LinkData
And then i tried
link = {
'link': link,
'call_to_action': call_to_action,
'child_attachments': child_attachments,
'message': message,
'multi_share_end_card': False
}
It works fine.
I want to be able to use urllib2.urlopen() or requests.get() with http://plus.google.com/* url's.
Using python, how would I go about doing that? I need to login first, but how?
The following code returns something along the lines of:
"Your browser's cookie functionality is turned off. Please turn it on."
Well, the cookie itself is created and, and I tested robots.txt, there are no diallows... I also tried switching user agents, no luck.
cookie_filename = "google.cookie"
email = raw_input("Enter your Google username: ")
password = getpass.getpass("Enter your password: ")
self.cj = cookielib.MozillaCookieJar(cookie_filename)
self.cj.load()
self.opener = urllib2.build_opener(
urllib2.HTTPRedirectHandler(),
urllib2.HTTPHandler(debuglevel = 0),
urllib2.HTTPSHandler(debuglevel = 0),
urllib2.HTTPCookieProcessor(self.cj)
)
urllib2.install_opener(self.opener)
login_page_url = 'https://www.google.com/accounts/ServiceLogin?passive=true&service=grandcentral'
authenticate_url = 'https://www.google.com/accounts/ServiceLoginAuth?service=grandcentral'
gv_home_page_url = 'https://www.google.com/voice/#inbox'
# Load sign in page
login_page_contents = self.opener.open(login_page_url).read()
# Find GALX value
galx_match_obj = re.search(r'name="GALX"\s*value="([^"]+)"', login_page_contents, re.IGNORECASE)
galx_value = galx_match_obj.group(1) if galx_match_obj.group(1) is not None else ''
# Set up login credentials
login_params = urllib.urlencode( {
'Email' : email,
'Passwd' : password,
'continue' : 'https://www.google.com/voice/account/signin',
'GALX': galx_value
})
# Login
resp = self.opener.open(authenticate_url, login_params).readlines()
print resp
self.opener.open(authenticate_url, login_params).readlines()
self.cj.save()
# Open GV home page
gv_home_page_contents = self.opener.open(gv_home_page_url).read()
print gv_home_page_contents
So I am trying to create a unique permalink each time that a person posts on my webpage and I want it to be relatively search engine friendly so I have made a little code to change the title to a good search engine title and it is working but then my handler cannot accept it. At least that is what I think is happening because the webpage just gives me a 404 error. The HTML works fine because when I redirect to a static page it all goes through. Here is the applicable code:
def post(self):
subject = self.request.get('subject')
content = self.request.get('content')
if subject and content:
p = Post(parent = blog_key(), subject = subject, content = content)
p.put()
id=str(p.key().id())
subject = str(subject)
subject = subject.replace(' ', '25fdsa67ggggsd5')
subject = ''.join(e for e in subject if e.isalnum())
subject = subject.replace('25fdsa67ggggsd5', '-')
subject = subject.lower()
url = '/blog/%s/%s' % (id, subject)
self.redirect('/blog/%s/%s' % (id, subject))
class PostPage(BlogHandler):
def get(self, post_id):
key = db.Key.from_path('PersonalPost', int(post_id), parent=blog_key())
post = db.get(key)
if not post:
self.error(404)
return
self.render("permalink.html", post = post)
class PersonalPost(db.Model):
subject = db.StringProperty(required = True)
content = db.TextProperty(required = True)
created = db.DateTimeProperty(auto_now_add = True)
last_modified = db.DateTimeProperty(auto_now = True)
user_id = db.StringProperty(required = True)
def render(self):
self._render_text = self.content.replace('\n', '<br>')
return render_str("post.html", p = self)
def blog_key(name = 'default'):
return db.Key.from_path('blogs', name)
app = webapp2.WSGIApplication([('/blog/([0-9]+)/([.*]+)', PostPage)]
And again it works when I just have it redirect to the main page and list them but not when I try to direct to the new SEO page.
UPDATE:
The test url I am using is setting
subject = "test-url"
id = "1234"
The app then directs me to www.url.com/blog/1234/test-url but it gives me a 404 error.
You define two groups in ('/blog/([0-9]+)/([.*]+) but your PostPage.get() only takes one.
Change it to def get(self, post_id, subject) or remove the second group ('/blog/([0-9]+)/[.*]+
I think you should have a look at the quotes on ur handler mapping, it seems inconsistent.
yours: app = webapp2.WSGIApplication([('/blog/([0-9]+)/([.*]+)', PostPage)]
try : app = webapp2.WSGIApplication(['/blog/([0-9]+)/([.*]+)', PostPage)]